How to use access token to like fanpage - facebook-graph-api

I have own access token and i would like create app, where user can like fanpage.
I tested request on graph.facebook.com. My request looks like this
http://i.stack.imgur.com/lkG7x.png
I read documentation form og.likes documentation on fb
It was not until I learn to handle fb api
How to sent such a request
curl -X POST \
-F 'access_token=USER_ACCESS_TOKEN' \
-F 'object=OG_OBJECT_URL' \
https://graph.facebook.com/[User FB ID]/og.likes

The og.likes action can refer to any open graph object or URL, except for Facebook Pages or Photos.
Source: https://developers.facebook.com/docs/opengraph/guides/og.likes
Use the Like Button Plugin instead.

Related

How to integrate a Google Natural Language API with Chatfuel?

My coding skills and familiarity with Google Cloud solutions are limited and I'm trying to consume a Machine Learning model from a chatbot build using the platform Chatfuel.
I've trained a Natural Language Machine learning model using Google NL and I wanted to use this code snippet provided in my model page:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
https://automl.googleapis.com/v1/projects/123456/locations/us-central1/models/ABC123:predict \
-d #request.json
I've then tried to pass this information in Chatbot like this:
The problem is it looks like I need to pass a token (API key seems not possible for this API) and I don't see how from the Chatfuel interface I could obtain a token for each request and pass it in my post request.
Edit: I've seen this post and created a service account but I don't see how to pass the credentials to Chatfuel.
How can I pass Google API service account credential to Chatfuel?
You should make a service account with Google Cloud.
It should give you a JSON with an API key, which is used to generate a new token every hour or so. Using the Google API for whatever server side language you are using (or just using the native http requests), you use the service key (which in general is loaded into your server as a .json file) to fetch a new token every hour; OR you can use Google Apps Script, if they have Chatfuel available (which I'm not sure if they do) and get the token there, and send it to your own app every 30 minutes or so via a trigger.
But the main thing is: using your service API key, you make an HTTP request to a certain api URL (available on with instructions from another page from that link above) every hour or so to generate a new token.
From the docs, that URL appears to be:
POST https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/SA-4#PROJECT-ID.iam.gserviceaccount.com:generateAccessToken
just replace, "`
SA-4#PROJECT-ID.iam.gserviceaccount.com
`"
with your own service account name
That's about it, its how it works for all Google Cloud APIs

Facebook API permissions issue for Instant Articles

I am trying to make a POST request to the Facebook API to create instant articles, like so:
curl \
-F 'access_token={access token}' \
-F 'html_source="<!doctype html><html>blah blah blah</html>"' \
-F 'published=true' \
-F 'development_mode=false' \
https://graph.facebook.com/{page-id}/instant_articles
I am an admin for the app, and when I debug my access token, the scope shows email, pages_show_list, pages_manage_instant_articles, public_profile, but the request returns this error:
{"error":
{"message":"(#200) Requires pages_manage_instant_articles permission to manage the object",
"type":"OAuthException",
"code":200,
"fbtrace_id":"Exyv2VtZ5m4"}
}
Anyone have any ideas about what's going on? Thanks and let me know if you need more info!
Solved! I added the version to the url.
https://graph.facebook.com/v2.7/{page-id}/instant_articles
When I first worked with Graph API I faced the same issue but that was in Android.
Although the solution in my case, user / admin have to sign in first and give permission to access facebook data using GraphAPI

django rest framework OAuth2 Toolkit

i use django rest framework and OAuth2 Toolkit in my django backend app. I registered users in django admin site. Whne i try to get access token with CURL for user i get error:
{"error":"invalid client"}.
my curl request is bellow:
curl -X POST -d "client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET&grant_type=password&username=myuser&password=mypass" http://localhost:8000/o/token/
Do you have the right secret and id and/or the right grant-type?
1) Go to <yoursite>/admin and login with your admin account
2) Go to <yoursite>/o/applications and choose your application
Now you can see your secret, id and grant type(should be 'password').
Also have a look at the client type(should be 'confidential')
Thank you fo your help I solve my problem. My right curl request is bellow:
curl -X POST -d "grant_type=password&username=USERNAME&password=PASSWORD" --user "CLIENT_ID:CLIENT_SECRET"

Facebook OpenGraph: Submitting an new action

I'm just starting out with Facebook SSO and OpenGraph. I have SSO working with my iOS app and now I'm starting to see how to publish OpenGraph actions.
I've set up a new Action Type and I need to submit it. When I do, I get the error:
You must publish at least one action to your Timeline using this action type. Review the documentation.
Ok, so I click the helpful documentation link and it tells me I want to do this:
https://graph.facebook.com/me/recipebox:cook?recipe=http://www.example.com/pumpkinpie.html&access_token=YOUR_ACCESS_TOKEN
So I translate that into this:
https://graph.facebook.com/me/fotoferret:hug?ferret=http://www.example.com/pumpkinpie.html&access_token=MY_ACCESS_TOKEN
fotoferret is my namespace, hug is my action
where MY_ACCESS_TOKEN is the value returned by:
https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=MY_APP_ID&client_secret=MY_APP_SECRET
When I pasted my translated URL I get this error back:
{
"error": {
"message": "An active access token must be used to query information about the current user.",
"type": "OAuthException",
"code": 2500
}
}
an this point I'm confused. I've tried publishing an action to my timeline, but it tells me a I need an active access token, which I've provided. So how can I publish an action?
When using an app access token please use the ID of the user not /me. You are doing actions on behalf of the app not directly of the user.
User Access Token
https://graph.facebook.com/me/fotoferret:hug?ferret=http://www.example.com/pumpkinpie.html&access_token=MY_ACCESS_TOKEN
App Access Token
https://graph.facebook.com/ID/fotoferret:hug?ferret=http://www.example.com/pumpkinpie.html&access_token=MY_ACCESS_TOKEN
When using the Graph Explorer be sure to switch the option to POST and not get GET. GET is set by default so it will return the actions not create one.
Or using cURL
curl -F 'access_token=MY_ACCESS_TOKEN' \
-F 'ferret=http://www.example.com/pumpkinpie.html' \
https://graph.facebook.com/ID/fotoferret:hug
If you have "Requires App Token to Publish" enabled and get
{"error":{"message":"(#15) This method must be called with an app access_token.","type":"OAuthException","code":15}}
It means you are using
curl -F 'access_token=MY_ACCESS_USER_TOKEN' \
-F 'ferret=http://www.example.com/pumpkinpie.html' \
https://graph.facebook.com/me/fotoferret:hug
Use MY_APP_TOKEN. If you get,
{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
it means you are using
curl -F 'access_token=MY_APP_TOKEN' \
-F 'ferret=http://www.example.com/pumpkinpie.html' \
https://graph.facebook.com/me/fotoferret:hug
You should use the numeric id
curl -F 'access_token=MY_APP_TOKEN' \
-F 'ferret=http://www.example.com/pumpkinpie.html' \
https://graph.facebook.com/ID/fotoferret:hug
If you get
{"error":{"message":"(#200) Requires extended permission: publish_actions","type":"OAuthException","code":200}}
The user doesn't have publish_actions actions in their set for me/permissions, it should be there as "publish_actions": 1 if it is not, grant the permission by selecting "Get Access Token" and choosing (you must change to suit in your app code scope as well)
It might be easier if you use the graph API explorer to generate an access token for you app and use that. That would at least eliminate any chance of error from your fetching the access token.

Help posting to users feeds

I have an app and I want to post to the users feed.
All the users have allowed publish_stream permission but I have no idea how to post to their feeds which I should be able to do even if the user is offline.
I want to use curl and the graph like this:
curl -F 'access_token=...' \
-F 'message=Hello, Arjun. I like this new API.' \
https://graph.facebook.com/arjun/feed
Do I simply use the access code I got when the users initially allowed me access, or do I have to get a new access code each time I want to post to their feed, if so, how do I do that?
Any help, much appreciated.
After the user authorized your application you get an access-token from facebook. You can use this token to post to the users-wall until he changes his password or removes your application from his application list.
I think you need to include your api-key in the request. Otherwise please provide the error message your getting!