我正在尝试更新Facebook统计信息以及照片。当我尝试更新没有图像的统计数据时,它成功运行但是当我添加图片网址时它失败。
$request = (new FacebookRequest( $session, 'POST', '/me/feed', array(
'message' => 'I love articles on benmarshall.me!',
)))->execute();
$response = $request->getGraphObject()->asArray();
以下代码不会返回任何错误,但无法将照片上传到Facebook
$request = (new FacebookRequest( $session, 'POST', '/me/photos', array(
'message' => 'I love articles on benmarshall.me!',
'source' => 'http://domain.online/demo/1.jpg',
)))->execute();
$response = $request->getGraphObject()->asArray();
我也尝试了以下代码,但它返回错误500。
require_once( 'facebook-php-sdk-v4-4.0-dev/autoload.php' );
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.2',
]);
$data = [
'message' => 'My awesome photo upload example.',
'source' => $fb->fileToUpload('/path/to/photo.jpg'),
];
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post('/me/photos', $data, '{access-token}');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();