我在将照片上传到Facebook页面上的相册时遇到问题。将照片上传到页面是没有问题的,但是对于相册来说它不起作用。
这里是代码(从示例中复制):
<?php
session_start();
require_once 'vendor/facebook/php-sdk-v4/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookRequestException;
// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication('app_id','app-secret');
$scope = array('publish_actions');
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( 'url' );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
/* make the API call */
$request = new FacebookRequest(
$session,
'POST',
'/page-id/albums?name=albumname/photos',
array (
'url' => 'url',
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
} else {
// show login url
echo '<a href="' . $helper->getLoginUrl() . '">Login</a>';
}
当我尝试这个时,我收到消息: 致命错误:未被捕获的异常&#39; Facebook \ FacebookAuthorizationException&#39; with message&#39;(#100)相册所有者的ID无效&#39;在...
有谁知道什么是错的?
答案 0 :(得分:1)
/page-id/albums?name=albumname
用于创建具有该名称的新相册。
要将照片发布到现有相册,您必须发布到/{album-id}/photos
。
有关详细信息,请参阅https://developers.facebook.com/docs/graph-api/reference/v2.1/album/photos#publish。