Facebook API: Can not block a user from a page - facebook

When blocking a user from a page via Facebook API getting valid response but can not understand what it means.
Request to block a user:
curl -i -X POST \
"https://graph.facebook.com/v14.0/1111666294606851/blocked?asid=%5B104062075441111%5D&access_token=totoken"
returns:
{
"104062075441111": false
}
For other users it returns true

Related

Why can't I generate user token in Instagram API?

I'm trying to use instagram api to show #'s on my webpage but i need to generate user token for instagram tester. I followed the documentatio (created an application, use my page url, sent invitation for instagram tester and accepted it) but when i click on generate token for instagram tester it displays a pop-up window to allow permissions, then it shows nothing. I tried with another account, creating a different application but the result is the same.
Facebook token generator seems to be broken, but you can generate your own long-lived access token following OAuth2 workflow (replace {} placeholders with your own values):
In your browser, go to:
https://api.instagram.com/oauth/authorize?client_id={your-client-id}&client_secret={your-client-secret}&redirect_uri={a-valid-redirect-url}&scope=user_profile,user_media&response_type=code
Login to your Instagram account and accept your application to access your data
You should be redirected to {a-valid-redirect-url}?code=xxxxx#_ then copy to {code} query string value without the #_ at the end
Use Postman to execute a POST request to https://api.instagram.com/oauth/access_token with x-www-form-urlencoded params
client_id: {your-client-id}
client_secret: {your-client-secret}
grant_type: authorization_code
redirect_uri: {a-valid-redirect-url}
code: {the code you extracted from query string}
You should get a short-lived access-token response such as:
{
"access_token": "IGQVxxxxxxxxxx…",
"user_id": xxxxxxxxxx
}
Exchange your short-lived access-token with a long-lived one: use Postman to execute a GET request to https://graph.instagram.com/access_token with query params:
client_id: {your-client-id}
client_secret: {your-client-secret}
grant_type: ig_exchange_token
access_token: {the short-lived access_token}
You should get a long-lived access-token response such as:
{
"access_token": "IGQxxxxx…",
"token_type": "bearer",
"expires_in": 5169852
}

Facebook Messenger open callback

Is there any way to get callback When users open messenger ?
Currently I am developing Facebook chat bot, for existing user on Facebook page
I want to show get started button, that's why i need some callback when user open
messenger
You don't need a callback to have Get Started button. All you need for this is to register the button with your app.
To do so, you send a curl as following:
curl -X POST -H "Content-Type: application/json" -d '{ \
"get_started":{ \
"payload":"<GET_STARTED_PAYLOAD>" \
} \
}' "https://graph.facebook.com/v2.8/me/messenger_profile?access_token=<PAGE_ACCESS_TOKEN>"
You may change GET_STARTED_PAYLOAD to any text you like - that is what Facebook is going to send to your webhook if the user clicks GET STARTED.
More information here and here.

facebook messenger send message api without the user initiating the chat

I have a facebook page, and a website too. I need to add a button to my website, like "SEND THIS ARTICLE ON MESSENGER". When the user clicks on it, I need to send the article data to the user on messenger.
How can I achieve that?
To achieve your goal, You must have to use SEND TO MESSENGER Button.
Ref.: https://developers.facebook.com/docs/messenger-platform/discovery/send-to-messenger-plugin/
Full process to implement:
1. Need to integrate Facebook Div in your site
2. Add Facebook script
3. Once Any User press the button than You got the webhook event from the facebook which contatin the PSID.
4. Through this PSID You can sent the messege to that id.
If you are sending message using curl than following is the code
curl -X POST -H "Content-Type: application/json" -d '{
"recipient": {
"id": "<PSID>"
},
"message": {
"text": "hello, world!"
}
}' "https://graph.facebook.com/v2.6/me/messages?access_token=<FB_PAGE_TOKEN>";

Facebook and Parse: Code 251, Error: Parse::InvalidSessionError

I'm trying to set up a chrome extension that uses a Facebook Access token to login to Parse using the JS api. As a proof of concept I tried following the example here with curl, but when I put in my access_token and expiration_date, the POST call returns {"code":251,"error":"Parse::InvalidSessionError"}
Specifically, I'm calling this from the OSX shell.
curl -X POST
-H "X-Parse-Application-Id: [my app id]" \
-H "X-Parse-REST-API-Key: [my rest api key]" \
-H "X-Parse-Revocable-Session: 1" \
-H "Content-Type: application/json" \
-d '{
"authData": {
"facebook": {
"id": "[my id as a string]",
"access_token": "[my token as a string]",
"expiration_date": "2015-10-26T07:45:16.579Z"
}
}
}' \
https://api.parse.com/1/users
I've googled around a bit, including reading the following posts, but after changing my settings on my Facebook app multiple times and re-authenticating, it is still throwing the same error.
Using FB user to login on parse. Error code: 251, Invalid Sesion Error
Parse Facebook login fails with error code 251
For the record, I've tried changing my "App Secret embedded in the client" Facebook setting to false, as well as my "Native or desktop app?" to both yes and no (I'm fairly sure it should be set to yes, as I'm using the desktop app FB login flow.) I've also added my facebook app to my parse app, and enabled Facebook integration on parse, as well as double checking my parse app and rest api keys.
Please let me know what else I should try, or what other information you need to assess this.
Two things were wrong with the way I was approaching this.
I was creating the "Expires_at" field by adding the "Expires_in" field (returned using this FB login flow) to the current time as calculated by my browser. In retrospect this was silly, as the expiration time is supposed to be exact, and network latency will change the calculated time by a bit.
I was using the wrong facebook ID for my request - there are two types of IDs now, and you need to use the correct one. See this link..

Need URL id for Facebook graph

I need to get the id of the URL posted to the wall, but the documentation says I can get the id from the the url I posted, but that id isn't usable because the id IS a url? Here is the code.
Just post to the Graph API:
curl -XPOST -F"id=https://your-url.com" \
-F"scrape=true" https://graph.facebook.com
It should return some JSON including the ID of the url:
{
"url":"https:\/\/your-url.com\/",
"type":"website",
"title":"https:\/\/your-url.com\/",
"updated_time":"2011-11-14T07:05:22+0000",
"id":"10150375340063123"
}