Upload image with facebook API

前端 未结 4 1326
终归单人心
终归单人心 2020-12-18 15:27

Question: How to upload an image from my webserver to facebook via FB API?

I\'m writing an application that retrieves images from the user\'s photo album, makes some

4条回答
  •  抹茶落季
    2020-12-18 15:48

    The code in this question use the outdated REST APIs, that will soon be discontinued.

    The correct way now is:

    $fbk = new Facebook(/* conf */);
    $fbk->setFileUploadSupport(true);
    
    //If you are executing this in a script, and not in a web page with the user logged in:
    $fbk->setAccessToken(/* access token from other sources */);
    
    //To add to an album:
    $fbk->api("/$albumId/photos", "POST", 
              array('source' => '@'. realpath($myPhoto), 'message'  => "Nice photo"));
    
    //To upload a photo directly (the album will be created automatically):
    $fbk->api("/me/photos", "POST", 
              array('source' => '@'. realpath($myPhoto), 'message'  => "Nice photo"));
    

    Remember the $fbk->setFileUploadSupport(true);

提交回复
热议问题