I'm just getting started with Facebbook API/OpenGraph and RestFB.
I created a custom object and action type on Facebook.
However, I don't quite get the concept of how RestFB works with publishing an action with an object.
I'm able to publish an action (complete) like this:
FacebookType publishMessageResponse =
facebookClient.publish("me/myapp:complete", Post.class,
Parameter.with("mycustomobject", "http://samples.ogp.me/xxxxxxxxxxxxx"),
What I don't understand is how to create an object with all necessary parameters and pass it into the publishMessage. In this case I just linked to the sample object that was provided by Facebook for illustration.
What I don't understand is how to create an object with all necessary parameters and pass it into the publishMessage.
Open Graph objects are basically just URLs.
You put all the necessary info into the HTML that this URL delivers, into the Open Graph meta elements. (See OG docs for this.)
Then, when publishing your action on an object, you just give that object’s URL, and Facebook will fetch the data from there. (Unless you have some additional custom properties, for which you can also give the values while publishing the action).
Related
I'm trying to post custom story with applink. I have defined action type complete and an object step - so user can "complete a step" inside app. Then I defined one step using Object Browser. How can I add applink via Object Browser?
There is a field al:android, which I assume needs to be filled with data. There is a hint stating that I should put there JSON object or array. So I did.
Tried with:
{"package":"com.example.myapp","class":"com.example.myapp.MainActivity","app_name":"My Example App"}
I've got error:
Is there a way to make this work?
You can use Facebook Mobile Hosting API to create App Link objects. Here is documentation: https://developers.facebook.com/docs/applinks/hosting-api
Should get in return something like this: {"id":"643402985734299"}, this is the ID of hosted applink - try with it.
I'm making a Facebook canvas application, and I want give some of the objects there "Facebook presence" - I want to allow users to comment on them and to like and share them via Facebook.
I understand I need to do it via OpenGraph. So I created an object type on my OpenGraph and named it item. I've tried to create an instance of item with the following POST request:
url:
https://graph.facebook.com/https://graph.facebook.com/me/objects/ilender_local-test:item
body:
method=POST&object=%7B%22type%22%3A%22%5C%22ilender_local-test%3Aitem%5C%22%22%2C%22title%22%3A%22My+First+Item%22%7D&access_token=...
The access_token, ofcourse, is the access token for my app.
Now, the result I get is a simple JSON false - no error message - but I assume I failed since when I succeed in creating an object on Facebook I usually get the id of the newly created object.
What am I doing wrong?
My stupidity knows no end. https://graph.facebook.com/https://graph.facebook.com? What was I thinking...
When you want to "unlike" a built-in like action on an open graph object, you have to send an HTTP DELETE with the id of the like story itself. But that requires either:
Querying the graph for the ID of the story before deleting it, or
Stashing the ID that's returned when you create the like in the first place.
Neither of these are satisfying solutions. It would be nice to be able to do this all in a single request, preferably with nothing more than the URL of the liked object.
Because this modifies the graph, the Graph API has to be used, right? AFAIK, FQL is still read-only.
Half the battle is figuring out a way to use the Graph API to look up the ID of the like story given the URL of the liked object:
GET http://graph.facebook.com/me/og.likes?object=http://url.to/your/object&fields=id
Once you have that, you can name it in a batch query, then refer to it from the DELETE request using JSONPath (details here under "Specifying dependencies between operations in the request"):
POST http://graph.facebook.com/
batch=[
{"method":"GET", "name":"like_id", "relative_url":"me/og.likes?object=http://url.to/your/object&fields=id"},
{"method":"DELETE", "relative_url":"?id={result=like_id:$.data[0].id}"}
]
tl;dr: No, there isn't a way.
Calling publish_action using the JS SDK is actually pretty straightforward. However (from the little info I gleaned from reading the documentation), there's no way for me to query facebook to have it return the action instance ID for an object that I have already published... is there?
Example:
User A loads the page, and the page sends an FB.api call to /me/news.reads, which returns an action instance ID.
User A reloads the page, and the page again sends an FB.api call to /me/news.reads, but this time, the Graph API returns:
{
error: {
code: 3501,
message: 'blahblahblah... already associated... blah blah'
type: 'OAuthException'
}
}
Pretty standard stuff, and expected, since I turned off the ability to publish the same URL multiple times.
Now then, is there any way for me to retrieve a previously published action instance ID from the Graph API by passing in the URL, or is it up to me to handle the returned action instance ID (from the original publication attempt) and save it to a database? I was hoping I wouldn't have to do that...
No, there is no way to retrieve instances of published actions other than:
Accessing action by id:
http://graph.facebook.com/ACTION_ID
Accessing all instances published by specific user:
http://graph.facebook.com/USER_ID/NAMESPACE:ACTION (NAMESPACE:ACTION may be replaces by the name of one of built-in actions like news.reads, music.listend, etc.
If you want to access details of published actions connected/referencing specific object you'll need to save that data on your end for later usage.
I defined a custom Open Graph action (e.g. "drive") and a custom object ("car") with custom properties ("color", "make"), then added the meta tags to the object page and verified with the Object debugger. I also published few actions in my timeline.
When I use the action API to view the "drive" actions ("/me/[name_space]:drive") I see all the actions and the Objects with their default properties (ids, titles..) but no custom properties.
How can I retrieve the Objects with all their custom properties?
It is probably too late, but I encountered with the same problem today.
It seems that the custom action /me/[name_space]:drive only provides the standard properties, but I found that if you also include the object type you can retrieve it with the custom ones:
GET https://graph.facebook.com/me/recipebox:cook/recipes
or in your example:
GET https://graph.facebook.com/me/[name_space]:drive/car