Uploading photo to another user's profile in Facebook using PHP - php

Can you post a photo to the wall of a friend of the logged-in user using the FB Graph API? I could find no posts that answered this exact question but if there are please point me in the right direction.
I have tried the code found in answers to this question to post a photo, but no matter what user id is used in the call to api, the photo gets added to an album on the logged-in user's profile.
Is it possible to post a photo to another user's profile - just like one any user can manually add to someone's Wall Photos? i.e, a post that will have type: "photo" in the graph API instead of type "link".

Even while going through the old publish documentation, they specify you can only include attachments using links to the media you'd like to attach and not by uploading directly through the API. Looks like this is the route you're going to have to go (using the link property you've already mentioned)

Related

Facebook Graph API - Pulling photos from tagged posts

I'm using the Facebook Graph API in PHP to pull tagged and uploaded photos from a user. We are currently using the /me/photos... endpoint to grab both kinds of photos. On our side, the code roughly looks like...
$api_call = $this->facebook->api("me/photos?date_format=U&since=$since_time&until=$current_time&limit=".$photo_limit);
// Valid response was received
if(isset($api_call['data'])){
// Get the photos the user is tagged in
$user_tagged_photos = $api_call['data'];
}
Variables in the URL string are just vars we set. We then just do the same thing for uploaded photos.
However, what my team has realized is that users also sometimes are tagged in posts that have associated pictures with them. So, maybe they are tagged in a post with a picture of them, but they aren't physically tagged in the photo.
Is there a method available for grabbing photos from posts a user is tagged in? The graph api reference for /post/ lists "picture" as a field but describes it as:
The picture scraped from any link included with the post.
Which is not what I want. I want the attached picture, just can't seem to find a way to access...
Thanks in advance for any help.
In that case, object_id in the Post object that gets returned when making a request to /{user-id}/tagged should be the ID of any photo/video that is attached to the post the user is tagged in.
Check the docs for the /post endpoint.

Facebook Cover Photo API using PHP

Has Facebook released any api for facebook cover photo?
I want to implement it using PHP language.
EDIT
I want to upload cover photo in facebook timeline using graph api PHP
There is an api for updating the cover photo on a page
http://developers.facebook.com/docs/reference/api/page/
It asks for a photo id which i guess is the id of a photo from the users album.
Actually, it is not possible to change the profile picture directly via Facebook Photo Graph API as no section mention about that.
However, we can do a trick by uploading user’s photo to Facebook via the API then redirect the user to uploaded photo URL with 1 added in querystring parameter as below:
http://www.facebook.com/photo.php?pid=xyz&id=abc&makeprofile=1
“&makeprofile=1″ is the main thing here and xyz/abc will be returned by Facebook. By adding the parameter, Facebook will auto change the profile picture of the current user with the uploaded picture above.
For more info:
http://4rapiddev.com/facebook-graph-api/php-change-facebook-profile-picture-with-graph-api/
You can upload photo to an album via graph api. Get the new photo id and redirect user to this url
"http://www.facebook.com/profile.php?preview_cover=" + photo_id
before that, you should inform the user that he/she will be redirected to facebook to page where they can set new cover photo (they need to confirm the change, click the save button). It's not perfect solution, and not fully covered api but it's best way out there asfaik.

Is it possible to upload photo to the friend's wall via Graph API?

Reading multiple posts and tutorials I assumed that this should be possible. After all if one can post a message to friend's wall via API, why shouldn't he be able to post an image? But in my app, I'm not able to do it. Despite of posting the image to a specific user with a specific id, it for some reason get's uploaded and posted to my (to a connected user's) wall.
Is it possible at all?

Facebook API/PHP - Is it possible to change a user's profile image via FB Graph API?

Is it possible to set/change a user's facebook profile image through the graph API?
I can't find a specific API method, but it is possible to upload an image to a user's album (http://developers.facebook.com/docs/reference/api/photo). Can I set the user's profile image to an image uploaded to their album?
Edit:
Same question asked in reference to REST API
Can I set a users profile image using the Facebook API?
No, And here's a comment from a guy at facebook:
The Original Link - you have to press show comments
We can do a trick by uploading user’s photo to Facebook via the API then redirect the user to uploaded photo URL with makeprofile=1 added to the list of query strings:
facebook.com/photo.php?pid=xyz&id=abc&makeprofile=1
Check Auto Change Facebook Profile Picture to get PHP example and demo.
Currently this is possible by redirecting the user to the mobile profile pic change url, https://m.facebook.com/photo.php?fbid=[fb photo id]&prof&ls=your_photo_permalink
The previous work around, using the facebook.com/photo.php?pid=[fb photo id]&makeprofile=1 url no longer works.
To the best of my knowledge and experience: No.
See the "Publishing" section here: http://developers.facebook.com/docs/reference/api/photo
Requires the publish_stream
permission.
To publish a photo, issue a POST
request with the photo file attachment
as multipart/form-data.
You can publish an individual photo to
a user profile with a POST to
http://graph.facebook.com/PROFILE_ID/photos
We automatically create an album for
your application if it does not
already exist. All photos from your
application will be published to the
same automatically created album.
You can publish a photo to a specific,
existing photo album with a POST to
http://graph.facebook.com/ALBUM_ID/photos.
The last sentence states you can publish to an existing album, so if you're trying to update the user's profile picture (not sure from the way you stated your question), try getting the album ID for the user, then publishing to that.

Facebook: How to add a Tag to a Fan page in the Caption of the Photo uploaded to users profile

I have seen a Fan page wall being tagged in a photos caption.
http://www.facebook.com/photo.php?fbid=165019486869988
Notice its in the Caption itself, and its a Fan page that was tagged, not a person.
How was this done? I actually cant even see how to do it manually on Facebook.
Can it be done in a Facebook PHP App? If so how?
So when my application posts to the users "Application Photo Album" the caption would have a link back to my apps fan page or app page.
This would all involve databases, and I have done something like this before. It is pretty involved the way facebook does it because they also link back to the tagged users page.
You would have to have a unique user ID for each user and a unique photo ID for each photo.
When a person pulls up the image the web site would query the MySQL Database and look for the record that matches the Photo ID, then it would look for the tagged User ID's that are attached to that Photo ID, which would be stored under that database record when the user was tagged.
The web site would then echo out the results of the database query to retrieve all of the tagged User ID's and you would have to then make the User ID's appear as the users name, which would require a function to take that User ID and query another database that will retrieve the users actual name and return it to the script.
The question you asked is very general and I can go on all day about the technicalities behind it, but I hope this gave you a general idea of how it can be done with PHP/MySQL.
Please let me know if you have any questions!!
I figured out that you can tag a fan page if you actually upload the image via your wall "Post Picture" then in the status message as your posting it you can tag the fan page #FanPage just like when you tag a friend in your status message.
Still not able to do this via programming.
Well i found a simpler solution to the same that uses the graph api
http://developers.facebook.com/docs/reference/api/photo/
You can specify which user to tag using two methods: in the URL path as PHOTO_ID/tags/USER_ID, or in a URL parameter as PHOTO_ID/tags?to=USER_ID. To add several tags at once, you can specify a tags property which contains an array of tags like so PHOTO_ID/tags?tags=[{"id":"1234"}, {"id":"12345"}]. Currently, you cannot tag a Page in a photo using this API.
Tagging a photo requires the user_photos and publish_stream permissions, publish_stream is optional - if not present, the tag will go through Tag Review of the tagged person if s/he has this privacy setting enabled. Tagging a photo supports the following parameters.
Hope this resolves the issue

Categories