How to add attachments to a post Facebook API - facebook-graph-api

When I look at the JSON data of a post which has several photos, I see that, this is done by using attachments/subattachments.
I want to post a data with several pictures and to do this, I want to take the advantage of attachments.
When I use "object_attachment" field for the post (to page feed), it creates only one attachment. Adding several "object_attachment" fields have no effect, only the first photo is used.
I want help on how to create attachment for a post and then add this attachment to the post.
Facebook says, attachments may be added to the posts to the post by "attachment_id" field.
Thanks to eveone who helps.

Related

Replicate a Facebook page and all its content

I would like to achieve the following:
GET all posts from a page and their related content (attachments, likes, visibility, tags, shares, comments, creation time...)
POST all that content in a new page
Assuming that I am admin of both pages.
I know that it's pretty straight forward to loop over the feed of a page and get all the posts' information. However, I'm not so sure about the POST part:
I guess that Facebook doesn't allow to "clone" people's
like/shares/comments below each post, on their behalf?
Considering that I will delete the first page, will all attachments disappear from Facebook's servers as well?
You cannot post in behalf of another user. And you cannot get all information you need with the Graph API.
What about renaming the page? If you like to delete the first page and clone it before, it looks like a rebranding or something ...

Tagging users in user feed post using graph API

On the Graph API page it shows a table showing the arguments we can use to create a new post to a feed
/PROFILE_ID/feed
Publish a new post on the given profile's feed/wall
message, picture, link, name, caption, description, source, place, tags
We want to be able to post to a users wall and tag their friends.
i.e. User 1 is doing something with User 2 and 5 others
What format should the tag attribute take?
For those who are interested:
tags is sent as an array of FB user ids
tags can only be added if there is a place associated with the post also
you have to post a Checkin to add place and tag friends
On Graph API Explorer you can use the below parameters:
/me/feed?message=<text-message-after-encoded>&place=<page-ID-of-location>&tags=<facebook-user-id,facebook-user-id,...>

Share album photo in Page Feed with geotargeting

I need to post a photo already present in a page's Photo Album to the same page's Feed, in a way similar to the Share functionality - which means with the bigger display, and allowing me to geotarget the post.
I've tried several approaches (among others, simply specifying "type": "photo"), but somehow always end up with a Feed post "type": "link" rather than "type": "photo" as generated by Facebook when sharing a photo.
Any help would be greatly appreciated...
AFAIK, the only way to do that is to post to '/me/links' (instead of '/me/feed') and set the 'link' to 'http://www.facebook.com/photo.php?fbid=<id_of_the_photo>'. That will effectively share the photo in the user's feed, showing a bigger picture. You can add a personal message (using the 'message' field) but I don't think it's possible to geotag a shared photo.
Posting to '/me/feed' with 'type: photo' only works if the user is the owner of the photo (in that case, set 'object_id' to the photo id).

What's a RESTful way of presenting a form?

I understand most of how a RESTful site design should function, but in implementing a blog cannot decide the best way to present the form to insert a new blog post. Would example.com/posts/create be reasonable? This feels like the "create" is not restful, like it's putting information into the URI that should be simply represented by PUT/POST.
How would others do this?
Have a look at Rails Routing for the Rails view on this.
Verb URL Controller Action Used For
GET /photos/new Photos new return an HTML form for creating a new photo
POST /photos Photos create create a new photo
So, in your situation, GET /posts/new to get the new post form, but POST /posts to create a new post.
The point is, you're POSTing a new blog post, but to do that you need to GET the form that will enable you to do this. In a way, the new blog post form is just another (static) resource.
If you don't like the way that URL feels, then change it to:
GET http://example.com/posts/createform
Use a POST to submit the information for the insert, and then have the page do a redirect to the with the new ID in the URL. You don't want to have the new information on the URL since a user refreshing the URL will post twice.

Requesting Posts and Photos in a single request

I'd like to know if there's a way to request a page's feed and also the pictures in each post. Getting each one separately isn't hard:
PAGE_ID?fields=id,name,cover,fan_count,posts
POST_ID?fields=full_picture
I've tried using batch. I wasn't able to get both in one request, I ended up with only the photos but not the posts (data) associated with.
Found a way to do it, thanks to https://stackoverflow.com/a/27524411/2124535
Graph API request:
PAGE_ID/posts?fields=picture,full_picture,attachments,description,message
or even simpler:
PAGE_ID/posts?fields=full_picture,message