I am trying to post an action using Facebook Open Graph API based on the Facebook documentation. When I do the following :
curl -X POST \
"https://graph.facebook.com/app/myNamespace:myAction" \
-F "access_token=$APP_TOKEN" \
-F "myObject=https://myhost.com/objectid"
I get the following error :
{"error":{"message":"(#200) Requires extended permission: publish_actions","type":"OAuthException","code":200}}
I have obtained a valid 'App Token' using this Faceboo documentation. The document states that actions can be published using App Tokens.
Btw, I am able to successfully post actions using user-access-token as follows :
curl -X POST \
'https://graph.facebook.com/me/myNamespace:myAction' \
-F 'myObject=https://myhost.com/' \
-F 'access_token=user-access-token'
Any Help is greatly appreciated.
You're trying to post to an Open Graph action as the app, which is not possible.
Unfortunately, there is no documentation to that explictly says this, but here is someone who tried to do the same thing.
If you read the documentation you posted, you'll see two main points. First, app tokens are for publishing information on the feeds of user's who have given permission to the app to do so, and app tokens are for some other basic "maintenance" type stuff for the app itself. There is nothing in there that support the idea that app tokens can be used for anything like posting regular Open Graph actions.
Related
I've spent a lot of time trying to send a game request from the (latest) JS API, using the Graph API v2.8, but nothing seems to work.
I've used only common OG, since custom OG are deprecated. When I use "turn" instead of "send" as the action type, my request works, since the "turn" requests don't require an object id, so I guess the problem comes from my OG.
I first created an action like this:
curl -X POST \
-F "access_token=*a user access token*" \
-F "game=*my game id*" \
https://graph.facebook.com/v2.8/me/games.plays
And then sent a game request using it the returned id in the "object_id" field. And this is the result I got:
Facebook response after calling FB.ui
Which doesn't provide any information...
So I tried to make a game object instead of an action. I figured "maybe you can't use actions in this context", and since game.achievement is the ONLY game object available, I made an achievement object, like this:
curl -X POST \
-F "access_token=*my app access token*" \
-F "object={\"fb:app_id\":\"*my app id*\",\"og:type\":\"game.achievement\",\"og:url\":\"*object's URL*\",\"og:title\":\"*A title*\",\"og:description\":\"*A description*\",\"og:image\":\"*A link to an image*\",\"game:points\":\"1\"}" \
https://graph.facebook.com/v2.8/app/objects/game.achievement
This is the result that I got:
Facebook response after calling FB.ui
Which makes no sense, because the object was created using an app access token, and that my app IS a game. So this statement makes no sense.
And now, I'm lost. I have no solution left, no new idea to try. I don't know what to do... The documentation is obviously missing information. They didn't even bother making a documentation for the games.plays action...
I need someone who knows how to use this damned API to help me figure this out, because right now, I'm just completely stuck.
Thanks in advance, community.
I'm attempting to have multiple title and descriptions for a same endpoint, one per language.
Trying to follow this documentation: https://developers.facebook.com/docs/opengraph/guides/internationalization#objects
I have a server that detects when the client is a bot, for example facebook bot, and it renders a single file with the title and description metas, and the following localization metas. I have a file for each language, and I set og:locale depending on the localization fb_locale that I recieve on the queryparams.
meta(property="og:locale" content="en_gb")
meta(property="og:locale:alternate" content="es_es")
meta(property="og:locale:alternate" content="it_it")
How can I have multiple language for the same endpoint?
This is my testing app and endpoint I'm trying to translate: https://webapp-server-21b.herokuapp.com/marcp
It seems that it crawls it properly, but does not display the preview in the language I expect when I share it on FB or in the debugger of facebook.
If I perform :
curl -X POST -F "id=https://webapp-server-21b.herokuapp.com/marcp" -F "scrape=true" -F "locale=en_gb" "https://graph.facebook.com" -s
or:
curl -X POST -F "id=https://webapp-server-21b.herokuapp.com/marcp" -F "scrape=true" -F "locale=es_es" "https://graph.facebook.com" -s
I get the expected title in the corresponding expected language, but when I share on facebook or in the debugger it's always in english, the default locale.
Thanks!
I am trying to figure out if the following is possible through the various Facebook APIs:
Create a Post on a Page through the API (I know that's possible:)
Boost that Post through the Ad API (I read that it's possible but I
can't really find the API that would let me do that. if you know it,
please point it out! Thanks!)
Once boosted, is there a way I can pull the boosted post information
from the original post? I assume that once boosted, the boosted post
is a different version of the original post, right?
I can get post stats through the Insight API and I can get boosted
post stats through the various Ad stats API. Do the post stats only
apply to the post and the boosted post stats only apply to the
boosted post or are they all one set of stats that applies to both?
Thanks in Advance!
Everything you are looking to do is available trough both the Graph API and the Marketing API.
1) Yes this is possible, as you pointed out. You can read more here
2) I would suggest that you read through the Marketing API doc I linked above to find out the full structure of an ad. But in short, an ad is split into the following 4 objects:
Ad Campaign: This is simply a grouping of Ad Sets which all have a similar business purpose as defined by the campaign objective.
Ad Set: An ad set is a group of ads that share the same daily or lifetime budget, schedule, bid type, bid info, and targeting data.
Ad Group: An ad object contains the data necessary to visually display an ad and associate it with a corresponding ad set. Each ad is associated with an ad set and all ads in a set have the same daily or lifetime budget, schedule, and targeting. Creating multiple ads in each ad set will let us optimize their delivery based on variations in images, links, video, text or placements.
Ad Creative: An ad creative object is an instance of a specific creative which is being used to define the creative field of one or more ad groups.
3) When a post has an ad created based on it there is not "duplicate" post created for the purpose of the Ad. If you want to only get paid/boosted information on the post then the best way to do this would be using the Ads Insights API.
4) When you pull stats from the insights API you will see metrics with 'paid' appended to them, for example 'post_impressions_paid'. This will return you the number of paid impressions (i.e. from an ad) but it will not give you any information on which ad caused those impressions. The Ad Insights API's will only return impressions, likes, comments etc caused by the ads that serve the post, they will NOT return organic actions.
Here is a quick run down of cURL commands that will create a campaign to boost a Post, but before trying them I would fully read the Marketing API docs so you understand whats happening.
// First we need to get the Ad Account from a user
curl https://graph.facebook.com/{USER_ID}/adaccounts&access_token={TOKEN}
// Now we can create our Ad Campaign. Response: {"id": "CAMPAIGN_GROUP_ID"}
curl \
-F 'name=my campaign group' \
-F 'campaign_group_status=PAUSED' \
-F 'objective=POST_ENGAGEMENT' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/adcampaign_groups
// Using the Campaign Group ID we can create an Ad Set. Response: {"id": "AD_SET_ID"}
curl \
-F "name=My Adset" \
-F "bid_type=CPC" \
-F "bid_info={'CLICKS': 500}" \
-F "campaign_status=ACTIVE" \
-F "daily_budget=2000" \
-F "campaign_group_id=<AD_CAMPAIGN_ID>" \
-F "targeting={'geo_locations':{'countries':['US','GB']}}" \
-F "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/adcampaigns"
// Before we create an Ad Group, it is recommended to create an Ad Creative.
// Response: {"id": "CREATIVE_ID"}
curl \
-F "name=sample creative" \
-F "object_story_id=<POST_ID>" \
-F "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/adcreatives"
// Now that we have the Creative ID we can use that to create the final piece
// of the puzzle, the Ad Group. Response: {"id": "AD_GROUP_ID"}
curl \
-F "name=my ad" \
-F "campaign_id=<AD_SET_ID>" \
-F "creative={'creative_id':<AD_CREATIVE_ID>}" \
-F "adgroup_status=PAUSED" \
-F "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/adgroups"
I'm very new to Facebook (yeah, I'm the only one) but I'd like to publish messages in the wall programmatically using Python.
What do I need to do to achieve that? I'm very confused. I have seen that most question about this are focused on how to let an app interact in some way with Facebook, but I'd like to post as if I were a simple user (a user which happens to "own" that particular Facebook page). Do I really need to go and create an app? (By the way, I'm having problems even with that... it tells me that my account seems fake or invalid even after I validated it via SMS). I imagine that there is a simpler way, introducing my credentials, using a POST request but I haven't read something similar.
I would have thought this is what I needed, but it leads to a page to create an app.
Some pointers?
By the way, I got a token via a publish_stream permission in the Graph API Explorer (using the extended permissions tab). Seems like this permission doesn't have expiration date but it's not recommended. Is there a better choice for a token?.
Thanks
Facebook is a bit trickier than other sites it would appear.
While watching the POST tab under NET in Firebug, while logging in, I see the following POST parameters:
charset_test €,´,€,´,水,Д,Є
default_persistent 1
email myusername
lgnjs 1340241652
lgnrnd 182050_CuPx
locale en_US
lsd AVqwALVx
pass mypassword
persistent 1
timezone 240
I don't yet know what lsd paramater is, but I did find out what the lgnrnd was by viewing the source of the login page before I logged in. It appears to be there to make it more difficult to automate authentication.
You first want your script to scrape that login page for that value, store it in a variable. Then, a cURL example would be something like:
curl -L "https://www.facebook.com/login.php?login_attempt=1" \
--cookie-jar /tmp/cookies.txt \
--data-urlencode "email=myusername" \
--data-urlencode "lgnrnd=$lgnrnd" \
--data-urlencode "pass=mypassword"
and so forth, with all the parameters...
This is untested of course, and I don't know what some of those parameter values are yet, but you should get the idea from that. You could probably use a python module like Beautiful Soup or something to apply the above basic concept.
Then you would do the same thing, watching the NET tab to find the parameters sent when you post to your facebook wall, and put it all together.
Note that I'm storing and using cookies with curl's --cookie-jar option. You will need a way to save and use cookies with the request as well, which is why I showed that.
Hope that helps you get started anyway..
What about this?.
import urllib2, urllib
parameters = {}
parameters['access_token'] = MY_TOKEN
parameters['message'] = 'Hello world'
target = 'https://graph.facebook.com/MY_ID/feed'
parameters = urllib.urlencode(parameters)
handler = urllib2.urlopen(target, parameters)
while True:
if handler.code < 400:
print handler.read() # Gets post_id
break
elif handler.code >= 400:
print 'Error' # :-(
break
Are there problems with this? Maybe a better way? Comments?
Thanks
I have question about the beta Open Graph stuffs.
The documentation I am looking at is this https://developers.facebook.com/docs/beta/opengraph/
I successfully define custom objects and actions. However, I cannot figure out how to link current user with other users.
For example, say I define a custom action 'kick'. I want the current user to be able to 'kick' one of his/her friends.
The closest object I can think of is 'profile', but when I pass user_id, 'http://www.facebook.com/profile.php?id=', or http://graph.facebook.com/, it does not work.
This is the requests I tried
POST https://graph.facebook.com/me/myapp:kick?access_token=abc&profile=http%3A%2F%2Fwww.facebook.com%2F123
POST https://graph.facebook.com/me/myapp:kick?access_token=&profile=123
POST https://graph.facebook.com/me/myapp:kick?access_token=abc&profile=http%3A%2F%2Fwww.facebook.com%2Fprofile.php%3Fid%3D123
POST https://graph.facebook.com/me/myapp:kick?access_token=abc&profile=http%3A%2F%2Fgraph.facebook.com%2F123
This is the response I get
{"error":{"message":"An unexpected error has occurred. Please retry your request later.","type":"OAuthException"}}
The profile given is for an external website. They call it external profile. Pretty misleading terms.
As you can see I used the following
curl -F 'access_token=TOKEN' \
-F 'profile=http://graph.facebook.com/zuck' \
'https://graph.facebook.com/me/MYAPP:kick'
And it gave the above.
I guess you can fill the external profile with meta info from the Facebook users and it will show alright (for example I can send the profile URL facebook.com/zuck instead), but it seems backwards, inefficient and not the intended usage.
For example feeding it my link.
curl -F 'access_token=TOKEN' \
-F 'profile=http://facebook.com/username' \
'https://graph.facebook.com/me/MYAPP:kick'
But the thing is ... I am not a musician.
It does though seem to look alright in aggregation view.
Which is interesting/weird since one of objects shown in this picture is a Facebook profile, so you would think they would give an example with Facebook profiles as objects.
Though they did say
We are now extending the Open Graph to include arbitrary actions and objects created by 3rd party apps and enabling these apps to integrate deeply into the Facebook experience
Which most likely means they want you to create arbitrary objects outside of Facebook.
Can you still link to other users?
Yes, but through tagging using tags=FacebookID1,FacebookID2 but it will be in the form of
phwd kicked a musician with Friend1 and Friend2 on [APP NAME]