Upload images to a specific Facebook Album

前端 未结 2 1717
滥情空心
滥情空心 2021-01-05 22:24

I can create an album using facebook graph api by posting data to

http://graph.facebook.com/ALBUM_ID/albums

it returns an id, which is not

2条回答
  •  一整个雨季
    2021-01-05 22:43

    I have actually faced the exact same problem, but with Events. What happens is Facebook does not return the actual event ID (in your case, the Album ID), but instead there's a small offset (with a maximum of 10). So, here's the workflow you need to follow (in order to make it work!):

    1. Publish the album. Save the returned (fake) album id, fb_aid in your database.
    2. Query for all published albums of the current FB-logged-in user.
    3. Loop through the list of returned albums.
    4. Identify the actual album id as follows by testing if the offset is < 10.
    5. Save actual album id in the database.

    $fbAlbums = $this->facebook->api(array('method' => 'photos.getalbums'));
    $myAlbums = $this->Album->find('all');
    for ($i = 0; $i < count($fbAlbums); ++$i) {    
        foreach ($myAlbums as $myAlbum) {
            $aidOffset = abs($fbAlbums[$i]['aid'] - $myAlbum['Album']['fb_aid']);
            if ($aidOffset != 0     // Prevents fixing an already fixed album id
                && $aidOffset < 10  // Checks if this is a FB ID Screw up
               ) {
                $myAlbum['Album']['fb_aid'] = $fbAlbums[$i]['aid'];
                $this->Album->save($myAlbum);
                break; // Little optimization
            }
        }
     }
    

    Now your database has updated album IDs. Hurray! Developer: 1. Facebook API: 0.

    I know it's not pretty. I know there are so many potential problems with it. But it gets the job done until Facebook cares enough to fix its API.

提交回复
热议问题