问题
My users can decide if they want to upload to the main timeline of their page or into one of the page albums.
Everything works successfully, except the fact my images being uploaded to the Timeline Photos (default FB album) instead of the selected one.
$timelinealbum is "me" if the timeline is selected, and it's the "%album_id%", if one of the albums selected.
So the post url is "/me/photos" for timeline, and "/%album_id%/photos" for album. Debugged, working well. Photos still go to Timeline Photos...
(No error message as the upload is successful.)
Any idea?
Thanks in advance!
Here's the upload code for multiple images (silent mode):
foreach ($tarrvegl as $t) {
$turl = wp_get_attachment_url($t);
$linkDataInner = [
'message' => $message,
'source' => $fb->fileToUpload($turl),
'published' => false,
'access_token' => $page_access_token
];
try {
$response = $fb->post('/'.$timelinealbum.'/photos', $linkDataInner);
$graphNode = $response->getGraphNode();
$resparr[] = $graphNode['id'];
} 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;
}
}
回答1:
More update: the child_attachments method didn't upload the images to FB. A post generated with sidescrolled images, but the images are just linked from my page. Meanwhile the albums are empty:
http://imgur.com/a/XPjzp
I just gave up. If multiple images uploaded, I grab the first's FB ID, make a public post to the page with it (FB creates a link to the album), and just add a note to the bottom of the post about the amount of uploaded images.
After contacting FB developers and got some tips from them, I've found out there were some changes from january.
The "published" field is gone, and there is a "no_story" field now, which have to be "true", if "published" was "false".
(The "no_story" name is funny a little, as from january stories were gone as well from v2.8 if I remember correctly. Can't find that alert again. More funny thing: at "/page/feed" docs there's still "published", while "album_id/photos" is using the "no_story" field. #wehatelogic)
But - and this is more interesting - now it's possible to post multiple images within one query! Minimum of 2, maximum of 5 (or 10; see docs) images can be attached to one post, and maximum of 5 are being displayed on Facebook.
For this, you have to use a "child_attachments" array. (Unfortunately if you want to upload only 1 image, you have to use a completely different method. #wehateyou)
More info at Facebook for Developers
来源:https://stackoverflow.com/questions/41516241/facebook-graph-api-2017-image-uploaded-to-timeline-photos-instead-of-given-alb