Facebook c# sdk Invalid access token signature on FacebookClient

I have a problem about Facebook c# sdk.

When i try to connect with accesstoken it s giving a error message: (OAuthException) Invalid access token signature

My url is:

https://www.facebook.com/dialog/oauth?client_id=" + _appid + "&redirect_uri=http://localhost:51656/Register.aspx?scope=email,publish_stream,offline_access,create_event,user_about_me,user_activities,user_birthday,user_education_history,user_events,user_groups,user_interests,user_likes,user_location,user_notes,user_religion_politics,user_relationship_details,user_photos,user_status

My Code is:

    string _code ="";
    string _appid = "184604574912126";
    string _accesstoken;

    protected void Page_Load(object sender, EventArgs e)
    {
       if (Request.QueryString["code"] != null)
        {
            _code = Request.QueryString["code"].ToString();
        }
        if (_code != "")
        {
           _accesstoken = _appid + "|" + _code;
           vFB = new FacebookClient(_accesstoken);               
        }
        try
        {
            JsonObject vmyobject = (JsonObject)vFB.Get("/me");
        this line giving exaption.
     }

What am i missing?


您获取访问令牌的方式不正确,请参阅此代码

        string AP_ID = System.Configuration.ConfigurationManager.AppSettings["FacebookAppID"];
    string client_secret = System.Configuration.ConfigurationManager.AppSettings["FacebookAppSecret"];
    string mywebsite = System.Configuration.ConfigurationManager.AppSettings["FacebookAppSecret"];
    string oathPage = System.Configuration.ConfigurationManager.AppSettings["PostAuthorizeRedirectURL"]; 
    string redirect_uri = mywebsite + oathPage;
                string code = Page.Request.QueryString["code"];
            string link = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&code={1}&client_secret={2}&redirect_uri={3}", AP_ID, code, client_secret, redirect_uri);
            WebClient webq = new WebClient();
            string access_token = webq.DownloadString(link);
            int pos2 = access_token.IndexOf("&expires");
            if (pos2!=-1)
                access_token = access_token.Substring(13, pos2 - 13);
            else access_token = access_token.Substring(13, access_token.Length-13);

使用此方法从代码获取有效的access_token

 public string GetAccessTokenFromCode(string AppID, string AppSecret, string RedirectURL, string Code)
{
WebClient wc = new WebClient();
string u2 = "https://graph.facebook.com/oauth/access_token?client_id=" + AppID + "&redirect_uri=" + RedirectURL + "&client_secret=" + AppSecret + "&code=" + Code + "&state=anytexthere";
string access = wc.DownloadString(u2);
access = access.Substring(access.IndexOf("access_token") + 13);
if (access.Contains("&"))
{
string accesstoken = access.Substring(0, access.IndexOf("&"));
return accesstoken;
}

return access;

}
链接地址: http://www.djcxy.com/p/61600.html

上一篇: 用户访问令牌用于通过脸谱图进行搜索

下一篇: Facebook c#sdk FacebookClient上的访问令牌签名无效