2011-03-07 68 views
2

我想通過處理小程序在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

回答

0

您需要將用戶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