http post facebook图api处理

问题描述:

我想通过处理小程序在facebook用户的墙上张贴一些东西。首先,我通过Oauth身份验证为app_id和user_id获取用户的access_token。 我用这个code,谢谢豪尔赫http post facebook图api处理

现在我想发布在用户墙上的帖子。 我做一个HTTP POST请求https://graph.facebook.com/USER_ID/feed 这些论点 “的access_token”,“XXX;! “消息”, “检查......处理”

请求的响应是

executing request: POST https://graph.facebook.com/USER_ID/feed HTTP/1.1 
---------------------------------------- 
HTTP/1.1 403 Forbidden 
---------------------------------------- 
{"error":{"type":"OAuthException","message":"(#200) This API call requires a valid app_id."}} 

什么意味着什么? 我已经进入了一个有效的APP_ID ......否则我没拿到的access_token?

问候, 彼得

import org.apache.http.HttpEntity; 
import org.apache.http.HttpResponse; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.impl.client.DefaultHttpClient; 

void setup() 
{ 
    String url = "https://graph.facebook.com/USER_ID/feed"; 

    try 
    { 
    DefaultHttpClient httpClient = new DefaultHttpClient(); 

    HttpPost   httpPost = new HttpPost(url); 
    HttpParams  postParams = new BasicHttpParams(); 
         postParams.setParameter("access_token", "XXX"); 
         postParams.setParameter("message", "Check ... Processing!"); 
         httpPost.setParams(postParams);  

    println("executing request: " + httpPost.getRequestLine()); 

    HttpResponse response = httpClient.execute(httpPost); 
    HttpEntity entity = response.getEntity(); 


    println("----------------------------------------"); 
    println(response.getStatusLine()); 
    println("----------------------------------------"); 

    if(entity != null) entity.writeTo(System.out); 
    if(entity != null) entity.consumeContent(); 


    // When HttpClient instance is no longer needed, 
    // shut down the connection manager to ensure 
    // immediate deallocation of all system resources 
    httpClient.getConnectionManager().shutdown();  

    } catch(Exception e) { e.printStackTrace(); } 

    exit(); 
} 
+0

你是否获得了'publish_stream'权限?如果你不需要'access_token'! – ifaour 2011-03-08 08:48:27

+0

我做了这个请求:http://www.facebook.com/login.php?api_key=YOUR_API_KEY&connect_display=popup&v=1.0&next=http://www.facebook.com/connect/login_success.html&cancel_url=http:// www .facebook.com/connect/login_failure.html&fbconnect = true&return_session = true&req_perms = read_stream,publish_stream,offline_access,但http发布请求不起作用。 – 2011-03-08 09:20:51

+0

对于http://之间的空格感到抱歉,否则链接不会显示正确。 – 2011-03-08 09:23:55

您需要将用户ID包含在请求的URL中,而不是字面上的'USER_ID'。

,所以你既可以做:

String url = "https://graph.facebook.com/"+user_id+"/feed"; 

,或者使用快捷键,litereally:

String url = "https://graph.facebook.com/me/feed"; 

其中的Facebook着眼于用户ID的访问令牌中的 '我'

leiu