Uploading a picture to facebook

后端 未结 2 2057
耶瑟儿~
耶瑟儿~ 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.

提交回复
热议问题