2010-05-06 79 views
12

我已經創建了一個應用程序,現在我想用新的Graph API在我的一個朋友牆上發佈消息。這是否可行?如何使用FB Graph在提要(牆上)上發佈消息

我已經在使用oAuth和Graph-api來獲取我所有朋友的列表。 在http://developers.facebook.com/docs/api的API告訴我蜷縮https://graph.facebook.com/[userid]/feed閱讀飼料,但也告訴我HOWTO發佈一條消息:

curl -F 'access_token=[...]' -F 'message=Hello, Arjun. I like this new API.' https://graph.facebook.com/arjun/feed 

Ofcourse這不起作用!我不能找出爲什麼..

這裏是我的PHP代碼:

require_once 'facebook.php'; // PHP-SDK downloaded from http://github.com/facebook/php-sdk 
$facebook = new Facebook(array(appId=>123, secret=>'secret')); 
$result = $facebook->api(
     '/me/feed/', 
     array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..') 
); 

此代碼不拋出任何錯誤,我知道我是的access_token正確的(否則我便無法運行$ facebook-> API( '/我=的access_token?' $這個 - >的access_token。);?讓我userobject

有沒有人在那裏sucsessfully發佈使用圖形的API的消息然後我需要你的幫助!:-)

回答

18

好吧,我終於解決了這一點。感謝名單以phpfour您的幫助:-)

第一:我連接的URL看起來像這樣(用 「publish_stream」):

$connectUrl = $this->getUrl(
    'www', 
    'login.php', 
    array_merge(array(
    'api_key'   => $this->getAppId(), 
    'cancel_url'  => $this->getCurrentUrl(), 
    'req_perms'  => 'publish_stream', 
    'display'   => 'page', 
    'fbconnect'  => 1, 
    'next'   => $this->getCurrentUrl(), 
    'return_session' => 1, 
    'session_version' => 3, 
    'v'    => '1.0', 
), $params) 
); 

;我試圖通過

$result = $facebook->api(
    '/me/feed/', 
    array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..') 
); 

張貼到Facebook的但要做到這一點,正確的做法是包括一個或多個參數(「後」):

$result = $facebook->api(
    '/me/feed/', 
    'post', 
    array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..') 
); 
6

您將需要「publish_stream」擴展權限才能寫入Feed。以下是他們的完整列表:http://developers.facebook.com/docs/authentication/permissions

爲了得到擴展權限,獲得授權令牌以這樣的方式

https://graph.facebook.com/oauth/authorize? 
client_id=...& 
redirect_uri=http://www.example.com/callback& 
scope=publish_stream 
+0

今天我使用Facebook的:: getLoginUrl()授權的。我已經在「req_perms」下添加了「publish_stream」,但是我認爲這還不夠好:( – qualbeen 2010-05-07 13:32:53

+0

好吧,如果你被卡住了,你可以看看我最近的博客文章,我已經展示了一個工作示例:http: //bit.ly/cT40vV – 2010-05-07 13:42:32

+1

值得注意的是它應該是「publish_stream」,而不是「stream_publish」。請參閱http://developers.facebook.com/docs/authentication/ – 2010-10-29 20:22:35

0

這是舊的方式來獲得存取權限。在GRAPH首先我產生代碼鍵搭配:

$getLinkCode ='https://graph.facebook.com/oauth/authorize'. 
       '?client_id=YOUR_APPID'. 
       '&redirect_uri=YOUR_SITE'. 
       '&scope=publish_stream'; 

現在,當我們有代碼鍵我們可以生成的access_token從鏈接:

$getLinkToken='https://graph.facebook.com/oauth/access_token'. 
       '?client_id=YOUR_APPID'. 
       '&redirect_uri=YOUR_SITE'. 
       '&client_secret=YOUR_SECRET'. 
       '&code=CODE_KEY'; 

但這ACCESS_TOKEN張貼您的留言用戶不是應用程序...爲什麼?

如果你想發佈應用牆上使用:

$facebook->api('/YOUR_APPID/feed/', 'post', array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..')); 
1

除了CHF

發佈後:

$getLinkToken='https://graph.facebook.com/oauth/access_token'. 
       '?client_id=YOUR_APPID'. 
       '&redirect_uri=YOUR_SITE'. 
       '&client_secret=YOUR_SECRET'. 
       '&code=CODE_KEY'; 

我得到的迴應:

https://graph.facebook.com/oauth/access_token? 
    client_id=xxxxxxxxxxxxxx 
    &redirect_uri=myurl 
    &client_secret=xxxxxxxxxxxxxx 
    &code=xxxxxxxxxxxxxx 

沒有哪一個是access_tokenclient_secret或代碼

$facebook->api('/YOUR_APPID/feed/', 'post', 
array('access_token' => $this->access_token, 
'message' => 'Playing around with FB Graph..')); 
1

作爲鏈接說:enter link description here

<?php 
    $app_id = "YOUR_APP_ID"; 
    $app_secret = "YOUR_APP_SECRET"; 
    $my_url = "YOUR_POST_LOGIN_URL"; 
    $code = $_REQUEST["code"]; 
    if(empty($code)) { 
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
    . $app_id . "&amp;redirect_uri=" . urlencode($my_url) . "&amp;scope=email"; 
    echo("<script>top.location.href='" . $dialog_url . "'</script>"); 
    } 
    $token_url = "https://graph.facebook.com/oauth/access_token?client_id=" 
    . $app_id . "&amp;redirect_uri=" . urlencode($my_url) 
    . "&amp;client_secret=" . $app_secret 
    . "&amp;code=" . $code; 
    $access_token = file_get_contents($token_url); 
    $graph_url="https://graph.facebook.com/me/permissions?".$access_token; 
    echo "graph_url=" . $graph_url . "<br />"; 
    $user_permissions = json_decode(file_get_contents($graph_url)); 
    print_r($user_permissions); 
?> 
0

而不是使用下面的代碼

[facebook dialog:@"feed" 
andParams:params 
andDelegate:self]; 

採用如下方案

[facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 
相關問題