1

我无法将以下代码发布到用户 ID 为 514559322 的用户的墙上。但是,如果我将 $uid 的值替换为字符串“me”,我可以发布到我自己的墙上。

<?php
require_once "../src/facebook.php";

$app_id = "my app id";
$app_secret = "my app secret";
$uid = 514559322;

// Init facebook api.
$facebook = new Facebook(array(
        'appId' => $app_id,
        'secret' => $app_secret,
        'cookie' => true
));

// Get the url to redirect for login to facebook
// and request permission to write on the user's wall.
$login_url = $facebook->getLoginUrl(
    array('scope' => 'publish_stream')
);

// If not authenticated, redirect to the facebook login dialog.
// The $login_url will take care of redirecting back to us
// after successful login.
if (! $facebook->getUser()) {
    echo <<< EOT
<script type="text/javascript">
top.location.href = "$login_url";
</script>;
EOT;

    exit;
}

// Do the wall post.
$facebook->api("/$uid/feed", "post", array(
    message => "Hello win95",
    picture => "http://cdn.papyimg.com/wp-content/uploads/2011/03/Windows-95-500x312.png",
    link => "http://en.wikipedia.org/wiki/Windows_95",
    name => "Go windows 95",
    caption => "Caption - this is the best operating system in the world!"
));
?>

如何允许我的 php 脚本使用 uid 514559322 发布用户墙?

在 api 调用周围添加一个 try catch 循环后,这是我得到的异常消息:

OAuthException: (#1) An error occured while creating the share

那么在我的代码中,我在哪里提供身份验证信息?或适当的身份验证令牌?

4

2 回答 2

1

您的用户需要为“offline_access,publish_stream”验证您的应用程序(尽管现在已被替换,请参见此处http://developers.facebook.com/roadmap/offline-access-removal/)。

然后,您可以在 api 调用中注入令牌

$res = $facebook->api('/me/feed', 'POST', $post);

其中 $post 是 $access_token 和 $message 的数组

于 2012-07-28T22:31:21.783 回答
1

你忘记了access_token参数:

// Do the wall post.
$facebook->api("/$uid/feed", 'post', array(
    'access_token' => $facebook->getAccessToken(),
    'message' => "Hello win95",
    'picture' => "http://cdn.papyimg.com/wp-content/uploads/2011/03/Windows-95-500x312.png",
    'link' => "http://en.wikipedia.org/wiki/Windows_95",
    'name' => "Go windows 95",
    'caption' => "Caption - this is the best operating system in the world!"
));

或者,您需要offline_access许可,这不好,因为很快就会被弃用..

于 2012-07-28T22:33:03.813 回答