简体   繁体   English

WP7 Facebook SDK示例代码无效

[英]WP7 Facebook SDK Sample Code Doesn't Work

Does the current WP7 sample project work? 当前的WP7示例项目是否正常工作? I've downloaded it and entered my app id and secret key, which I know to work from a previous WM6.5 app. 我已经下载了它,并输入了我的应用程序ID和密钥,我知道可以在以前的WM6.5应用程序中使用它。 I get the facebook login page, and I log in. I get the page asking if I want to grant permission, which I do. 我得到了facebook登录页面,然后登录。我得到询问您是否要授予权限的页面,我这样做。

The code then throws a KeyNotFoundException while looking for the "access_token" key. 然后,该代码在查找“ access_token”键时引发KeyNotFoundException。 I've peppered the code with: 我在代码中添加了:

if (objectname.ContainsKey("access_code")) ... 如果(objectname.ContainsKey(“ access_code”))...

I've put this everywhere I can see an attempt being made to search for this key, to no avail. 我已经把它放到任何地方,我可以看到有人试图搜索此键,但无济于事。 The code still errors at the same point. 该代码仍然在同一时间错误。

Has something changed on the facebook side since this sample code was last tested successfully? 自上次成功测试此示例代码以来,facebook方面是否有所更改? Is there something else I should be doing? 还有什么我应该做的吗?

Many thanks 非常感谢

Here's a example how to use the Facebook SDK with WP7. 这是一个如何在WP7中使用Facebook SDK的示例。 So basically I got webBrowser1 on MainPage.xaml but at default it's hidden. 所以基本上我在MainPage.xaml上有了webBrowser1,但默认情况下它是隐藏的。

Code behind: 后面的代码:

void MainPage_Loaded(object sender, RoutedEventArgs e)
{

            string appId = "";
            string[] extendedPermissions = new[] { "publish_stream", "offline_access", "user_groups" };

            var oauth = new FacebookOAuthClient { AppId = appId };

            var parameters = new Dictionary<string, object>
                {
                    { "response_type", "token" },
                    { "display", "touch" }
                };

            if (extendedPermissions != null && extendedPermissions.Length > 0)
            {
                var scope = new StringBuilder();
                scope.Append(string.Join(",", extendedPermissions));
                parameters["scope"] = scope.ToString();
            }

            var loginUrl = oauth.GetLoginUrl(parameters);
            webBrowser1.Navigate(loginUrl);
            webBrowser1.Visibility = System.Windows.Visibility.Visible;
            webBrowser1.Navigated += webBrowser1_Navigated;
}
void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
    {
        FacebookOAuthResult result;
        if (FacebookOAuthResult.TryParse(e.Uri.AbsoluteUri, out result))
        {
            if (result.IsSuccess)
            {
                string _accessToken = result.AccessToken;
                webBrowser1.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                var errorDescription = result.ErrorDescription;
                var errorReason = result.ErrorReason;
            }
        }
    }

I think this might be the answer you're looking for: 我认为这可能是您要寻找的答案:

http://facebooksdk.codeplex.com/discussions/284103 http://facebooksdk.codeplex.com/discussions/284103

see also: http://facebooksdk.codeplex.com/workitem/5925 另请参阅: http : //facebooksdk.codeplex.com/workitem/5925

var jsonObject = new JsonObject();

if (returnParameter.ContainsKey("access_token"))
{
    jsonObject["access_token"] = returnParameter["access_token"];
}

If you're just logging in then there isn't a parameter called access_code that you need. 如果您只是登录,那么就不需要一个名为access_code的参数。

I suspect you need to be using access_token which is returned as part of the fragment after a login attempt. 我怀疑您需要使用access_token ,它将在尝试登录后作为片段的一部分返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM