Uncaught OAuthException: (#200), when trying to post on wall

前端 未结 1 1025
南方客
南方客 2021-01-07 11:21

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\';
$sec         


        
1条回答
  •  时光说笑
    2021-01-07 11:34

    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/

    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?

     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 ("");
    
    } 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();
            }
    
    }
    
    ?>
    

    0 讨论(0)
提交回复
热议问题