你好朋友,我制作了一个 facebook 应用程序,可以将照片上传到新相册中。我配置了 facebook 应用程序并编写了代码。它适用于测试用户。现在我可以看到,publish_actions 已获得批准,因为权限上没有错误迹象。但它仍然不适用于所有用户,仅适用于测试用户。
我正在分享你的代码: -
$fb = new Facebook\Facebook(['app_id' => 'xxxxxxxxxxxx',
'app_secret' => 'xxxxxxxxxxxxxxxxxxxx',
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error getting TOKEN : ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
// Logged in!
$_SESSION['facebook_access_token'] = (string) $accessToken;
$fb->setDefaultAccessToken($accessToken);
$batch = [
'photo-one' => $fb->request('POST', '/'.$albId.'/photos', [
'message' => 'Foo photo',
'source' => $fb->fileToUpload('img/2.jpg'),
]),
'photo-two' => $fb->request('POST', '/'.$albId.'/photos', [
'message' => 'Fool photo',
'source' => $fb->fileToUpload('img/1.jpeg'),
])
];
try {
$responses = $fb->sendBatchRequest($batch);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error UP PICS: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
foreach ($responses as $key => $response) {
if ($response->isError()) {
$e = $response->getThrownException();
echo '<p>Error! Facebook SDK Said: ' . $e->getMessage() . "\n\n";
echo '<p>Graph Said: ' . "\n\n";
var_dump($e->getResponse());
} else {
echo "<p>(" . $key . ") HTTP status code: " . $response->getHttpStatusCode() . "<br />\n";
echo "Response: " . $response->getBody() . "</p>\n\n";
echo "<hr />\n\n";
} }