-1

i made wordpress website in 2012 and since then i am using facebook graph api(php sdk) tool to upload pictures to users fb profile, now i dont know why its saying facebook redirected you too many times

here is the example link of picture where you can see upload to fb option

http://www.punjabidharti.com/punjabi/punjabi-sad/roula-kaavan-da/

This is my code in fb index file

    <?php
if(isset($_POST["source"]))
{
    try {
        $access_token=$facebook->getAccessToken();
        $graph_url= "https://graph.facebook.com/me/photos?"
      . "url=" . urlencode($_POST["source"])
      . "&message=" . urlencode($_POST['message'])
      . "&method=POST"
      . "&access_token=" .$access_token;
        $response=file_get_contents($graph_url);
        $json=json_decode($response);
      }
      catch (FacebookApiException $e) {
        error_log('Could not post image to Facebook.');
      }
}
?>

i am using api 2.0 and in base_facbook file

public static $CURL_OPTS = array(
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 60,
    CURLOPT_USERAGENT      => 'facebook-php-3.1',
      );

please help me

Ninder Chand
  • 389
  • 1
  • 5
  • 15

1 Answers1

0

Your question doesn't explain too much about you error, but as far as I know you are doing a GET request and it seems that the API request its a POST.

I recommend you to update your request to use the last API version and to do a POST request for example using curl as follows:

$data = "url=" . urlencode($_POST["source"])
  . "&caption=" . urlencode($_POST['message'])
  . "&access_token=" .$facebook->getAccessToken();

$endpoint = "https://graph.facebook.com/v2.4/me/photos";

$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$reply=curl_exec($ch);
curl_close($ch);

This snippet was not tested but I think it shows the idea.

Hope it helps!

darode
  • 140
  • 6
  • hi thanks for reply, sorry if you did nt understand my question, i think the problem starts when facebook upgraded the api v2.2 to 2.3 and in 2.2 version my code was working perfect, now i dont know how to solve these problem.. and i tried your code but still the same – Ninder Chand Apr 01 '17 at 17:21