2013-03-12 55 views
2

这是我的第一个话题,我希望你能帮助我(请用我的英语很好,因为我的第一语言是法语)THX :))获得一个应用程序访问令牌与Android FacebookSDK V3

我有一个问题,我试图通过Facebook Android Facebook SDK v3获得应用程序访问令牌,但迄今为止我还没有成功。

我已经看到了互联网上,让应用程序令牌,我们需要访问该链接:

https://graph.facebook.com/oauth/access_token client_id=*************&client_secret=***********************&%20grant_type=client_credentials 

所以我做了一个请求对象来获取应用程序令牌:

Bundle bundle = new Bundle(); 
bundle.putString("client_id", appId); 
bundle.putString("client_secret", appSecret); 
bundle.putString("grant_type", "client_credentials"); 

Request request = new Request(null, "oauth/access_token", bundle, HttpMethod.GET); 
Response resp = request.executeAndWait(); 

该对象的“响应”返回给我一个GraphObject,如下所示: GraphObject{graphObjectClass=GraphObject, state={"FACEBOOK_NON_JSON_RESULT":"access_token"}}

但访问令牌不包含在由请求者返回的响应中ST。

然而,当我启动在浏览器中的链接我得到这样一个页面: access_token=[the_access_token]

为什么我不能得到蒙山的响应是一回事吗? 我做错了什么?有没有人有办法解决吗?

非常感谢!

+0

我认为的事实,这个端点的反应是_not_ JSON可能是问题 - 如果您的请求对象希望它是JSON ,但得到别的东西,它可能会失败。消息FACEBOOK_NON_JSON_RESULT也表明了这一点。 – CBroe 2013-03-12 16:14:51

回答

-1

我有同样的问题。

访问令牌不是JSON类型。所以你不能使用facebook api的'request'和'response'。 你将有链接下的解决方案。

Show this link

或在代码中看到


public static void getAppAccessToken(){ 
    String url = "https://graph.facebook.com/oauth/access_token?client_id="+CLIENT_ID+"&client_secret="+CLIENT_SECRET+"&grant_type=client_credentials"; 
    InputStream is; 
    String result; 
    HttpClient httpclient = new DefaultHttpClient(); 
    HttpGet httpget = new HttpGet(url); 

    try{ 
     HttpResponse response = httpclient.execute(httpget); 

     HttpEntity entity = response.getEntity(); 
     is = entity.getContent(); 

     BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); 
     StringBuilder sb = new StringBuilder(); 
     String line = null; 

     while ((line = reader.readLine()) != null) { 
      sb.append(line); 
     } 

     is.close(); 
     result=sb.toString(); 
     result = result.split("=")[1]; 
     appAccessToken = result; 
    } 
    catch(Exception e) 
    { 

    } 
} 

+0

从不讨论你在其他人的问题,红色的常见问题解答以获得更好的理解,如果你回答这个问题,请提及它。 – Hamad 2013-11-21 08:23:30

相关问题