"(190) Invalid OAuth access token signature" with FacebookWebContext HasPermission
I just upgrated from the old facebook sdk to the new Facebook C# SDK 5.0.25 (RTW). I'm doing a simple login to my site with some exteded permissions such as email,read_stream,publish_stream,offline_access.
Everything works fine until I check for a permission: if (fbWebContext.HasPermission("email"))... When I do that I get : Facebook.FacebookOAuthException: (190) Invalid OAuth access token signature.
Are you facing that problem?
The following is the code that I'm using:JS:
FB.login(function (response) {
if (response.session) {
if (response.perms) {
// user is logged in and granted some permissions.
// perms is a comma separated list of granted permissions
} else {
// user is logged in, but did not grant any perm开发者_StackOverflow社区issions
}
window.location.reload();
} else {
// user is not logged in
}
}, { perms: 'email,read_stream,publish_stream,offline_access' });
C#:
var fbWebContext = FacebookWebContext.Current;
if (fbWebContext.IsAuthorized())
{
var permissions = new FacebookWebAuthorizer(fbWebContext).Permissions;
if (fbWebContext.HasPermission("email")) ...
Is there something wrong with this approach?
ThanksI use a different approach:
I don't declare a new variable for the FacebookWebContext. I don't check is IsAuthorized (to me it gave some problems inside an App).
So, if I were you I would simply try the following, which includes also an authorize request in case the user has not previously given the permissions. Hope this helps.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook.Web;
namespace FacebookCsharpDemo
{
public partial class askPerm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (FacebookWebContext.Current.HasPermission("email"))
{
//permissions given
processEmail();
}
else
{
var auth = new CanvasAuthorizer { Permissions = new[] { "user_about_me", "email" } };
if (auth.Authorize())
{
processEmail();
}
else
{
//show permissions error message - not really - facebook c# sdk will redirect the user to the cancelUrlPath defined in the web.config...
litEmail.Text = "You must authorize the Application, please try again";
}
}
}
private void processEmail()
{
var fb = new FacebookWebClient();
dynamic me = fb.Get("me");
litEmail.Text = me.email;
}
}
}
In the .aspx page just put a literal called litEmail.
精彩评论