facebook - Xamarin:最新 FB API 的问题

标签 facebook facebook-graph-api xamarin xamarin.ios xamarin-studio

最新FB登录API有3个参数

public unsafe virtual void LogInWithReadPermissions (string[] permissions, UIViewController fromViewController, [BlockProxy (typeof(Trampolines.NIDLoginManagerRequestTokenHandler))] LoginManagerRequestTokenHandler handler)

我正在使用 MVVMCross。对于 fb 登录,我尝试创建一个我所在的 View 的实例,并将其作为参数传递给 LogInWithReadPermissions()

View 模型:

private async void DoFacebookSignIn()
        {
            try 
            {               
                await facebookService. Login();
                DoAutoLogin();
            }
}

服务:

private readonly string[] permitions = new string[] { "email", "public_profile" };    
public async System.Threading.Tasks.Task LogIn()
            {
    LoginManager.LogInWithReadPermissionsAsync (permitions);

                LoginManagerLoginResult result = await LogInWithReadPermissionsAsync();

                if (result.IsCancelled)
                {
                    ServiceFactory.UserMessageService.ShowToast("Facebook login is canceled");
                }
            }

        private Task<LoginManagerLoginResult> LogInWithReadPermissionsAsync()
            {
                var tcs = new TaskCompletionSource<LoginManagerLoginResult> ();
                LoginManager.LogInWithReadPermissions (permitions,null, (LoginManagerLoginResult result, NSError error) =>
                {
                    if(error.IsNotNull ())
                    {
                        tcs.SetException (new IosErrorException(error));
                    } else 
                    {
                        tcs.SetResult (result);
                    }
                });

                return tcs.Task;
            }

但是它失败了,当我调用这个函数时,我是否需要从 Viewmodel 传递 View 信息?如何从 View 模型传递 View 实例?谁能帮忙?

更新

服务失败:

函数 LogInWithReadPermissionsAsync() 第 3 行:(LoginManager.LogInWithReadPermissions...)

没有给出任何错误。它只是崩溃。 Facebook API 版本:"Xamarin.Facebook.iOS"version="4.13.1"

更新 删除了未使用的代码。

最佳答案

我得到了解决方案。

代码很好,我只需要通过添加

将“网络请求的 Facebook 服务器列入白名单”
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>facebook.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>                
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>fbcdn.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

If you're recompiling with iOS SDK 9.0, add the following to your application's plist if you're using a version of the SDK v4.5 or older:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fbapi20130214</string>
    <string>fbapi20130410</string>
    <string>fbapi20130702</string>
    <string>fbapi20131010</string>
    <string>fbapi20131219</string>    
    <string>fbapi20140410</string>
    <string>fbapi20140116</string>
    <string>fbapi20150313</string>
    <string>fbapi20150629</string>
    <string>fbauth</string>
    <string>fbauth2</string>
    <string>fb-messenger-api20140430</string>
</array>
If you're using Facebook.MessengerShareKit from versions older than the v4.6 release, also add:

<string>fb-messenger-platform-20150128</string>
<string>fb-messenger-platform-20150218</string>
<string>fb-messenger-platform-20150305</string>
If you're using v4.6.0 of the SDK, you only need to add:

<key>LSApplicationQueriesSchemes</key>
<array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
</array>

如 Xamarin Facebook iOS SDK 中所述 here .

关于facebook - Xamarin:最新 FB API 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39169856/

相关文章:

c# - 我需要所有的 Android SDK 吗?我应该如何安装它们?

facebook - FQL 中的 "show tables"或 "describe"?

android - Facebook SDK 出现“ANDROID_BUILD_SDK_VERSION”错误

javascript - 如何动态设置 Angular JS 页面的元标签以进行 Facebook 共享?

ios - iOS SDK 中的多个请求

php - Facebook 登录 - 检查用户是否拥有有效/经过验证的 Facebook 帐户

listview - Xamarin ListView System.MissingMethodException : Method 'TextView.SetTextAppearance' not found

c# - 动态更改 TextView 的文本

facebook - 存储用户的 Facebook 访问 token

asp.net - 无法加载 URL : The domain of this URL isn't included in the app's domains in Facebook Login in ASP. NET MVC