简体   繁体   中英

post photo to facebook fun page with php

i am trying to post image to a facebook fun page, it's working will on my own wall but the fun page not and have no problem with posting text to fb fun page wall.

    $photo_url = "http://www.google.com/logo.png";

       $photo_caption = $text;

  $code = $_REQUEST["code"];

  //Obtain the access_token with publish_stream permission 
  if (!$code)
  { 
    $dialog_url= "http://www.facebook.com/dialog/oauth?"
      . "client_id=" .  $app_id
      . "&redirect_uri=" . urlencode( $post_login_url)
      .  "&scope=publish_stream";

    echo("<script>top.location.href='" . $dialog_url
      . "'</script>");
  } 
  else 
  {
    $token_url="https://graph.facebook.com/oauth/access_token?"
      . "client_id=" . $app_id
      . "&client_secret=" . $app_secret
      . "&redirect_uri=" . urlencode( $post_login_url)
      . "&code=" . $code;

    $response = file_get_contents($token_url);
    $params = null;
    parse_str($response, $params);
    $access_token = $params['access_token'];

    // POST to Graph API endpoint to upload photos
    $graph_url= "https://graph.facebook.com/{FUNPAGE-ID}/photos?"
      . "url=" . urlencode($photo_url)
      . "&message=" . urlencode($photo_caption)
      . "&method=POST"
      . "&access_token=" .$access_token;

    echo '<html><body>';

       echo file_get_contents($graph_url);

    echo '</body></html>';
  }

what can i do i think it's about the graph_url

You need to provide the data as encoded binary of the image itself. The URL parameter only adds a link to the POST as a part of the text or annotation, it will not retrieve and add the photo istelf from that URL!

add something like

...
"url=" . urlencode(file_get_contents($photo_url));
...

And: furthermore the Method must be POST, I'm not quite sure whether "file_get_contents" is going to POST the data and not just doing a GET as the name imposes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM