0

我需要使用 curl 从 Facebook 获取用户提要,我已经通过 curl 发送请求并得到了

Facebook returned HTTP Error Code: 404 error, follow is my code to connect facebook through curl 
<?php

$curl = curl_init();
curl_setopt($curl, CURLOPT_ENCODING , 'gzip, deflate');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_USERAGENT, "php-facebook-wall (https://github.com/dordotky/php-facebook-wall)");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url = "https://graph.facebook.com/".FACEBOOK_USER_NAME
    ."/".FACEBOOK_USER_OBJECT."?access_token=".FACEBOOK_APP_ID."|".FACEBOOK_APP_SECRET);

// Execute our curl request
$result = curl_exec($curl);

// Check that we didn't encounter any errors while processing
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ((!curl_error($curl)) && ($http_code == 200))
{
    $json = json_decode($result, true);
} else
{
    die("Facebook returned HTTP Error Code: ".$http_code);
}
?>
4

1 回答 1

1

在 Facebook 墙上查看此帖子图片示例。护理步骤:

  1. 在您的服务器上启用 SSL。
  2. 访问令牌在一段时间后更改,因此请使用最新的访问令牌。

    函数 facebook_upload($fb_oauth_token,$item_image) {

    $file = $item_image;
    
        $args = array(
            'access_token'=>urlencode($fb_oauth_token)
        );
    
        $args[basename($file)] = '@'.($file);
    
        $ch = curl_init();
        $url = 'https://graph.facebook.com/me/photos';
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
        $data = curl_exec($ch);
        //returns the photo id
        $response = json_decode($data,true);
        //print_r(curl_error($ch));
    
        //to check response
        //if($response[id]>0){
            // yes
        //}
        json_decode($data,true);    
    

    }

于 2013-03-05T10:01:57.560 回答