未捕获OAuthException:(#200),试图张贴在墙壁上时 [英] Uncaught OAuthException: (#200), when trying to post on wall

查看:110
本文介绍了未捕获OAuthException:(#200),试图张贴在墙壁上时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的数据库到我的Facebook的墙实现消息的发布简单。使用PHP-SDK:

I want to implement a simple posting of messages from my DB to my facebook's wall. Using php-SDK:

require_once 'lib/facebook.php';

$appID = 'xxx';
$secret = 'yyy';
$facebook = new Facebook(array(
    'appId'     =>  $appID,
    'secret'    =>  $secret,
));

$user = $facebook->getUser();
if (empty($user)) {
    header("Location: ". $facebook->getLoginUrl(array(
        'req_perms' =>  'publish_stream',
    )));
    exit();
}

$params = array(
    'message' => 'Hello, every one!',
);
$post_id = $facebook->api('/'. $user .'/feed', 'post', $params);

和我有。未捕获OAuthException:(#200)的用户无权执行此操作中...抛出的应用程序

And i have "Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action thrown in ...".

如果该脚本运行时,重定向到Facebook登录我没有登录,然后。 Сonfirm使用的数据没有给出。

If I'm not logged in, then when run this script, redirecting to the facebook login. Сonfirm the use of the data is not given.

推荐答案

下面是一个工作片段,但要确保你已经下载了最新的PHP SDK 3.0.1即
https://github.com/facebook/:如果你没有不已,然后从这里下载PHP-SDK /

Here's a working snippet, but make sure you've downloaded the latest PHP SDK i.e. 3.0.1 If you don't have already, then download it from here: https://github.com/facebook/php-sdk/

如果你去通过$ C $低于CS,你会pretty多了解它做什么,所以我不认为我有必要解释一下吗?

If you go through the codes below, you'll pretty much understand what it does, so i don't think i have to explain you more?

<?php

// Requires Facebook PHP SDK 3.0.1: https://github.com/facebook/php-sdk/
require ('facebook.php');

define('FACEBOOK_APP_ID',"YOUR-APP-ID");
define('FACEBOOK_SECRET',"YOUR-APP-API-SECRET");

$user = null;

$facebook = new Facebook(array(
    'appId' => FACEBOOK_APP_ID,
    'secret' => FACEBOOK_SECRET,
    'cookie' => true
));

$user = $facebook->getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected.

if($user == 0) {

    /**
     * Get a Login URL for use with redirects. By default, full page redirect is
     * assumed. If you are using the generated URL with a window.open() call in
     * JavaScript, you can pass in display=popup as part of the $params.
     * 
     * The parameters:
     * - redirect_uri: the url to go to after a successful login
     * - scope: comma separated list of requested extended perms
     */

    $login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));

    echo ("<script> top.location.href='".$login_url."'</script>");

} else {

    try {
            $params = array(
                'message'       =>  "Hurray! This works :)",
                'name'          =>  "This is my title",
                'caption'       =>  "My Caption",
                'description'   =>  "Some Description...",
                'link'          =>  "http://stackoverflow.com",
                'picture'       =>  "http://i.imgur.com/VUBz8.png",
            );

            $post = $facebook->api("/$user/feed","POST",$params);

            echo "Your post was successfully posted to UID: $user";

        }
        catch (FacebookApiException $e) {
           $result = $e->getResult();
        }

}

?>

这篇关于未捕获OAuthException:(#200),试图张贴在墙壁上时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆