Facebook - How to Upload Photos Via URL?

Discussion in 'PHP' started by thelastking, Mar 23, 2012.

  1. #1
    Hello, I want to create a site like myfbcovers.com actually not i mean i know how to create a website and all. but this is not a problem for me the problem is i want to directly upload the pics to the "Cover" album on facebook.

    For example i have WordPress installed on my website. i want to upload Pictures on Facebook via URL's. MY image Url is:

    http://example.com/wp-content/timeline-cover-1.jpg

    Here is the code i am using rite now:

    <?php
          $app_id = "12354";
          $app_secret = "1213243434";
          $post_login_url = "http://example.com/sdsds";
          $album_id = "1234224";
          **************$photo_url = "http://example.coom/wp-content/timeline-cover-1.jpg";**************
          $photo_caption = "my caption";
    
      $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/" 
          . $album_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>';
      }
    ?>
    PHP:

    So From above code i am able to upload "test.jpg" to facebook but now the problem is I don't want to upload one image, i want to upload lot of images so i don't want to change "$photo_url = "http://example.coom/test.jpg";" this code for new photos any help would be appreciate!
     
    thelastking, Mar 23, 2012 IP
  2. TopoRadar

    TopoRadar Well-Known Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    113
    Digital Goods:
    1
    #2
    if you want the MOD to transform wordpress (and other cms) into facebook timeline covers WP CMS i sell you the plugin for 45 euro
    pm me for demo
     
    TopoRadar, Mar 23, 2012 IP