2012-09-26 503 views
0

我想擴展我的Facebook訪問令牌,以下是我所做的。但是,我無法獲得令牌擴展,並且當我檢查facebook accesstoken調試器時,它仍然顯示該令牌將在一小時內過期。無法擴展Facebook訪問令牌

有什麼想法?

private string appId = "my app id"; 
    private string appSecret = "my app secret"; 
    private string returnUrl = "http://localhost:1868/callback"; 
    private string _scope = "user_about_me,publish_stream,user_videos,user_photos"; 

    [Test] 
    public void GetFacebookLoginUrl() 
    { 
     var fb = new FacebookClient(); 
     dynamic result = fb.GetLoginUrl(
      new 
       { 
        client_id = appId, 
        client_secret = appSecret, 
        redirect_uri = returnUrl, 
        response_type = "code", 
        scope = _scope 
       } 
      ); 
    } 

    [Test] 
    public void exchangeCodeForAccessToken() 
    { 
     var fb = new FacebookClient(); 
     dynamic result = fb.Get("oauth/access_token", new 
     { 
      client_id = appId, 
      client_secret = appSecret, 
      redirect_uri = returnUrl, 
      code = "got the code after user accepts the request" 
     }); 
    } 


    [Test] 
    public void ExtendExpiryTimeOfAccessToken() 
    { 
     var fb = new FacebookClient(); 
     dynamic result = fb.Get("oauth/access_token", new 
     { 
      client_id = appId, 
      client_secret = appSecret, 
      grant_type = "fb_exchange_token", 
      fb_exchange_token = "token from preview method" 
     }); 
    } 

解決方案

後去檢查從用戶的帳戶的一切相關應用決策意識。 有一點需要注意, 上面的代碼實際上獲得了一個「長期存取」的訪問令牌,它有效期爲60天,並且它不能被擴展。

如果使用Facebook client-side authentication,那麼可以使用「ExtendExpiryTimeOfAccessToken」示例對其進行擴展。

回答

2

如果您最初在脫機訪問折舊之前的幾個月前開始開發應用程序並進行簽名,則可能會受到此錯誤的影響。

https://developers.facebook.com/bugs/341793929223330

如果受到影響,你需要取消授權的應用程序,然後再試一次,這並不影響新用戶。

+0

是的,我認爲這是原因,我必須取消授權,然後一切都開始有意義。 – Eatdoku

+2

希望Facebook能夠儘快解決這個問題,但是考慮到目前爲止我已經採取了多長時間了,我並沒有屏住呼吸 – ArthurGuy

+0

@ArthurGuy你的意思是每個用戶都必須取消授權/刪除應用程序並重新添加它? – jrummell