Facebook Graph API - get a photos album ID

后端 未结 9 2164
小蘑菇
小蘑菇 2020-12-31 09:32

I\'m writing an application that uploads a photo to facebook. I\'m not supplying an album ID so an album is created on behalf of my app.

My question is: how do I get

相关标签:
9条回答
  • 2020-12-31 09:44

    Jimmy Sawczuk's answer is close, but doesn't work because FQL Photo table columns aid and pid are Rest/FQL API ids, not Graph API ids.

    Fortunately the object_id and album_object_id columns in this table are indexable (contrary to the documentation) so this should give you both Rest/FQL & Graph ids for the album:

    select aid, album_object_id from photo where object_id = ${GRAPH_PHOTO_ID}
    

    In general object_id fields in Rest/FQL API responses are Graph API id (except for photo notifications, where it's the Rest/FQL id).

    Re HonkyHonk's answer: not all photo link urls have a set parameter; in this case I think you can find the Rest/FQL API photo id from its other parameters, and then use Rest/FQL API to get the album id:

    • For users with 32-bit user-ids: calculate (id << 32) | pid
      • eg for http://www.facebook.com/photo.php?pid=7518353&id=549683637 this gives 2360873244068853905
    • Otherwise concatenate id, _ and pid
      • eg for http://www.facebook.com/photo.php?pid=155052&id=100002937903251 this gives 100002937903251_155052

    It would help a lot if Facebook could document something about the two types of ids. Also the Graph API Photo schema should include the album's Graph API id.

    0 讨论(0)
  • 2020-12-31 09:49
    function get_album_id_by_album_name($album_name){//return array of data
        $fql = 'SELECT aid, owner, name, object_id FROM album WHERE owner=me() and name="'.$album_name.'"';
        $param = array(
            'method'    => 'fql.query',
            'query'     => $fql,
            'callback'  => ''
        );
        $fqlResult = $this->facebook->api($param);
        return $fqlResult;
    }
    
    0 讨论(0)
  • 2020-12-31 09:52

    Richard Barnett's solution works well for me, I use this as an FQL query through the Graph API to get a JSON response like I would for any other Graph API query:

    https://graph.facebook.com/fql?q=select+album_object_id+FROM+photo+WHERE+object_id='[PHOTOID]'
    

    This returns:

    {
       "data": [
          {
             "album_object_id": "10150531092908837"
          }
       ]
    }
    

    Then you can access the album ID using:

    <?php
    
    $strPhotoAlbumID = $objFacebookAPI->data[0]->album_object_id;
    
    ?>
    

    This is the cleanest solution i've found as Facebook constantly change the format of their photo and album URLs so parsing these with RegEx wont work as a long term fix.

    0 讨论(0)
  • 2020-12-31 09:53

    I ended up just using the legacy REST api since the album ID is passed with the link to the image in the server response. I then used a regex to pull the id out.

    Not the best solution and I wouldn't recommend it but I feel its better than adding another several server requests to the code.

    0 讨论(0)
  • 2020-12-31 09:54

    Long, clunky, but theoretically valid way: http://graph.facebook.com/userid/albumswill get you a list of all the albums the user lets you see, then you can search the album objects (api here) for created_times that match the time you created the album, which you can store when you create the album.

    This is almost certainly a horrible way to do it, but it should work.

    0 讨论(0)
  • 2020-12-31 09:56

    If I'm understanding you correctly, you have the photo ID but need the album ID. You could try using the photo FQL table with the following query:

    SELECT aid, pid FROM photo WHERE pid = '<your photo id>'
    
    0 讨论(0)
提交回复
热议问题