2010-05-06 208 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]; 
相关问题