Reputation: 5770
I am playing with the facebook sdk, and want to allow our users the ability to post an image to their albums, but NOT the ability to upload the image.
Essentially, we have a dynamic page for logged in users that creates dynamic images on the fly.
Checking over the facebook SDK , I can get everything to work fine, if I allow the user to "upload" an image, but I cannot figure out how to attach the image that is already on the webpage ..
eg. lets say image on page is https://stackoverflow.com/images/my_image.jpg
In the facebook SDK: ( snipped code ) - for uploading an image
if(empty($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
. "&redirect_uri=" . urlencode( $post_login_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// Show photo upload form to user and post to the Graph URL
$graph_url= "https://graph.facebook.com/me/photos?"
. "access_token=" .$access_token;
echo '<html><body>';
echo '<form enctype="multipart/form-data" action="'
.$graph_url .' "method="POST">';
echo 'Please choose a photo: ';
echo '<input name="source" type="file"><br/><br/>';
echo 'Say something about this photo: ';
echo '<input name="message"
type="text" value=""><br/><br/>';
echo '<input type="submit" value="Upload"/><br/>';
echo '</form>';
echo '</body></html>';
So my question is, is there a way we can send a particular image , rather than upload an image within the above form ?
This could be the most obvious question known to man, I just am going google eyed trying to figure it out.
Upvotes: 0
Views: 94
Reputation: 47996
You'll only be able to post a link to an image in this way. If you want to post the actial image to Facebook, you'll have to download the image to your server first.
Something as simple as file_get_contents(PATH_TO_IMAGE)
will work just fine. You can always remove the file from your server once it's posted to Facebook.
There are a few methods detailed here on how to upload a photo without the upload form that is given in the documentation.
Upvotes: 1