0

I've run over all related topic, but couldn' find the answer for this: Is it possible to store an apps photos only in its own page album? Please mind that every user should upload photos to the same album. I've seen that apps can create album at the users/pages profile, but it would be nicer to store everything in one place.
I'm getting the following error:

Uncaught OAuthException: (#120) Invalid album id (base_facebook.php line 1038)

code:

public function setPageToken($userId = 'MY_USER_ID',
        $pageId = 'APP_PAGE_ID')
{
    // get logged in all page
    $args = array
    (
        'fileds'    => 'id,access_token',
        'scope'     => 'manage_pages,publish_stream'
    );
    $accounts = $this->api('/'.$userId.'/accounts','get',$args);
    // fetch the desired page access token
    foreach($accounts['data'] as $k => $v)
    {
        if($v['id'] == $pageId)
        {
            $token = $v['access_token'];
            break;
        }   
    }
    return $token;
}

Notes:

  1. my app ID is not equal to my apps page ID
  2. $accounts return value is empty

1 Answer 1

0

Theoretically, here is what you need to do:

  1. Get Page access token with permissions to upload photos.
  2. Hard-code or otherwise store the latter access token.
  3. Next time user uploads a photo using your HTML form you will need to use the latter access token to upload the photo to the page album.

Note, that theoretically, this doesn't require to authorise the user who is uploading the photo. However, if the question is whether you can upload a photo to a third-party page on user's behalf – you cannot.

Furthermore, note that if you are using Facebook PHP SDK, the default access token will be that of the presently active session (the user). Therefore you will need to manually change it to the Page access token or issue cURL request.

$ch = curl_init();
$url = "https://graph.facebook.com/" . $album_id . "/photos?access_token=" . $access_token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$retdata = curl_exec($ch);
echo($retdata);

upload photo to page timeline Facebook SDK

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.