2014-02-19 68 views
0
試圖重新定向,以獲得新的訪問令牌中出錯說當

格式不正確的訪問令牌190錯誤

(OAuthException - #190) Malformed access token AQClEC8NbS1tbO4_HzqqZwVy2Inrk5I7vBpszPDPN0dVOV0ekurwNEpqzlWe2hQzl2KNZ5BwiSvL16bDPhR5IxFeJXEXBdM67uky7iwKbYKIVoRF__iyayyXBgcIp939gEZNtCUxyO4ZKZHQ9xmEwDstaOgq_bAvtygwv3YUeEYD9wftsytMZYwVxDO7rjq-2i3-XCYj643-6_1yKZ0dDahAB00iBqJqw1xiZ-l1kzStmA_pwMwO5dtBHZozp-L2hp0JEeTL0Fhc5CG1zbJ8Om6kyKBWyZuc0AtOrdSjgcBQBv9hQSF5pwsMZvFDGcjiwSc 

什麼可能可能是這個問題我這樣做的方法來重定向:

string redirecturl = @"https://graph.facebook.com/oauth/authorize?client_id=507061112747022&redirect_uri=http://localhost:63695/FacebookChatApi/Default.aspx"; 
    Response.Redirect(redirecturl); 

和我讀的訪問令牌如下:

string accessToken=Request["code"]; 
var client = new FacebookClient(accessToken); // here is where the error occurred 
  1. 這是獲取客戶端訪問令牌的正確方法嗎?
  2. 爲什麼根據Facebook的調試工具讀取code

回答

0

當這個錯誤發生,你token不是一個令牌,但一個URL來代替:https://developers.facebook.com/tools/debug/og/object?q=AQClEC8NbS1tbO4_HzqqZwVy2Inrk5I7vBpszPDPN0dVOV0ekurwNEpqzlWe2hQzl2KNZ5BwiSvL16bDPhR5IxFeJXEXBdM67uky7iwKbYKIVoRF__iyayyXBgcIp939gEZNtCUxyO4ZKZHQ9xmEwDstaOgq_bAvtygwv3YUeEYD9wftsytMZYwVxDO7rjq

我不知道你得到它誰,爲什麼你得到它而不是訪問令牌 - 你沒有顯示足夠的代碼。從我所看到的,我相信你不正確地產生你的redirecturl。以下是我的項目中的一段代碼 - 請試試看,並告訴我它是否適用於您:

// 1. redirect user to the login page: 
var redirectUri = "http://localhost:63695/FacebookChatApi/Default.aspx"; 

var service = new FacebookClient(); 
var loginUrl = service.GetLoginUrl(new { 
    client_id = ConfigurationProvider.FacebookAppId, 
    client_secret = ConfigurationProvider.FacebookAppSecret, 
    redirect_uri = redirectUri, 
    response_type = "code", 
    scope = "manage_pages, publish_actions, user_photos, publish_stream" // Add other permissions as needed 
}); 

Response.Redirect(loginUrl); 

// 2. And when user authorizes, get the access token 
// NOTE: code executes on FacebookChatApi/Default.aspx page 
var redirectUri = "http://localhost:63695/FacebookChatApi/Default.aspx"; // must be the same as in the login call! 
var fb = new FacebookClient(); 
dynamic result = fb.Post("oauth/access_token", new 
{ 
    client_id = ConfigurationProvider.FacebookAppId, 
    client_secret = ConfigurationProvider.FacebookAppSecret, 
    redirect_uri = redirectUri, 
    code = code 
}); 

var accessToken = result.access_token; 
相關問題