2010-09-14 89 views
0

我想在android上構建一個XMPP客戶端,我已經使用Digest-MD-5進行了身份驗證,但是當我嘗試將其轉換爲X-FACEBOOK-平臺失敗。Facebook聊天 - X-FACEBOOK-PLATFORM身份驗證

+1

你可以提取您的問題的相關部分到您的問題的文字,請? – 2010-09-15 14:59:12

回答

3

所以基本上X-FACEBOOK-PLATFORM認證只使用訪問令牌的一部分。這被稱爲會話密鑰。

訪問令牌由「|」分隔字符,所以您拆分訪問令牌並僅採用位於中心的字符。請參閱下文。

** * *** | a681464febcefb8* - ** |* ** * **

long callId = new GregorianCalendar().getTimeInMillis()/1000L; 

      String sig = "api_key=" + apiKey 
          + "call_id=" + callId 
          + "method=" + method 
          + "nonce=" + nonce 
          + "session_key=" + sessionKey 
          + "v=" + version 
          + appSecret; 

      try { 
       sig = MD5(sig); 
      } 
      catch (NoSuchAlgorithmException e) { 
       throw new IllegalStateException(e); 
      } 

      String composedResponse = "api_key=" + URLEncoder.encode(apiKey, "utf-8") 
             + "&call_id=" + callId 
             + "&method=" + URLEncoder.encode(method, "utf-8") 
             + "&nonce=" + URLEncoder.encode(nonce, "utf-8") 
             + "&session_key=" + URLEncoder.encode(sessionKey, "utf-8") 
             + "&v=" + URLEncoder.encode(version, "utf-8") 
             + "&sig=" + URLEncoder.encode(sig, "utf-8"); 
0

我從來沒有FB聊天與我appSecret工作,但使用sessionSecret代替。您可以使用古老的REST API獲取它。

http://developers.facebook.com/docs/reference/rest/auth.promoteSession/

這種方式可以讓您的appSecret作爲祕密。另外值得注意的是X-FACEBOOK-PLATFORM認證在第一次嘗試中很少成功,但通常需要3-6次重試。打我爲什麼雖然因爲我使用相同的會話密鑰和祕密..