Uploading a picture to facebook

后端 未结 2 2055
耶瑟儿~
耶瑟儿~ 2021-02-10 02:00

I am trying to upload a image to a gallery on a facebook fan page, here is my code thus far,

$ch = curl_init();

        $data = array(\'type\' => \'client_cr         


        
相关标签:
2条回答
  • 2021-02-10 02:49

    Ok, got it working, here is the code, assuming that you have a valid session going.

        $token = $session['access_token'];
    
        //upload photo
        $file= 'photo.jpg';
        $args = array(
        'message' => 'Photo from application',
        );
        $args[basename($file)] = '@' . realpath($file);
    
        $ch = curl_init();
        $url = 'https://graph.facebook.com/me/photos?access_token='.$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);
        $data = curl_exec($ch);
    

    This will upload the specified image to the session holders gallery, it will create a album if there is not one present, also you can access the token via the session array as demonstrated above. Hope this helps someone out.

    0 讨论(0)
  • 2021-02-10 02:54

    Probably your application doesn't have needed permissions.

    To request permissions via OAuth, use the scope argument in your authorization request, and include a comma separated list of all the permissions you want to request.

    http://developers.facebook.com/docs/authentication/permissions

    0 讨论(0)
提交回复
热议问题