Reputation: 21
Does the current WP7 sample project work? I've downloaded it and entered my app id and secret key, which I know to work from a previous WM6.5 app. I get the facebook login page, and I log in. I get the page asking if I want to grant permission, which I do.
The code then throws a KeyNotFoundException while looking for the "access_token" key. I've peppered the code with:
if (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? Is there something else I should be doing?
Many thanks
Upvotes: 2
Views: 852
Reputation: 1275
Here's a example how to use the Facebook SDK with WP7. So basically I got webBrowser1 on MainPage.xaml but at default it's hidden.
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;
}
}
}
Upvotes: 1
Reputation: 65586
If you're just logging in then there isn't a parameter called access_code
that you need.
I suspect you need to be using access_token
which is returned as part of the fragment after a login attempt.
Upvotes: 0
Reputation: 31880
I think this might be the answer you're looking for:
http://facebooksdk.codeplex.com/discussions/284103
see also: http://facebooksdk.codeplex.com/workitem/5925
var jsonObject = new JsonObject();
if (returnParameter.ContainsKey("access_token"))
{
jsonObject["access_token"] = returnParameter["access_token"];
}
Upvotes: 0