how to use facebook Sharing audiences API? - facebook

how to use facebook Sharing audiences API ?
https://graph.facebook.com/{audienceid}/adaccounts
i have tried running it in graph api explorer i didn't understand what are the attributes need to be supply and usage.

the Facebook Ads API call for sharing your audiences would be something like this:
Add's Ad Account Ids provided in the below call
HTTP POST: https://graph.facebook.com/{audienceid}/adaccounts/
Post Params:
'adaccounts' = array('adActId1','adActId2')
Delete Ad Accounts from the Audience with below call
HTTP DELETE: https://graph.facebook.com/{audienceid}/adaccounts
Refer: View This

I have tried this it works fine!
import requests
import json
params = {'access_token': 'youraccess_token' ,'adaccounts': [youraddaccount]}
r = requests.post('https://graph.facebook.com/{audienceid}/adaccounts', data=params)
print r.json()

Success result using postman
It only worked when adding access token to url, not worked when adding
access token to post body.

Related

Facebook Graph API (#190) This method must be called with a Page Access Token

I get data from the Facebook insights via Facebook Graph API more than year. And recently started all my requests (like {id}/insights) to return with an error: (#190) This method must be called with a Page Access Token.
But the Access token contains scopes manage_pages,read_insights.
Any ideas?
manage_pages,read_insights
This will give a user access_token , that u can use to manage pages & check insights,
But a page token became required for any /insights endpoint since 5th feb 2018
Use your manage_pages scope & user_token to get a Page access token
Send a get request to this endpoint
GET /{page-id}?fields=access_token
Output
{
"access_token": "{your-page-access-token}",
"id": "{page-id}"
}
You can use the returned access token to call /insights endpoint now.
As I cant add comment I'll write it here.
Field name is access_token which you can check here with your page id.
https://developers.facebook.com/tools/explorer/?method=GET&path=page-id%3Ffields%3Daccess_token&version=v2.12
For PHP
If you had your script in PHP, using Facebook SDK for PHP and now it brokes, you just need to retrieve token and pass it instead of access/refresh token you were using.
//Retrieve new 'page access token'.
$token = $fbApiClient -> get( "/{$pageId}?fields=access_token") -> getGraphNode()-> asArray();
//$q is your insights query which was working until now :(
//But with page acces token it will work again.
$response = $fbApiClient -> get( $q, $token['access_token']) -> getGraphEdge();
//(...) rest of script.
I think its easily adaptable to other languages too. Also you can (and propably should) store page access token and use it wherever you need, instead of retrieving it each time.

Facebook API For Pulling Reviews

Has anyone seen a full example of how to pull facebook reviews using the graph api.
According to the docs:
A page access token is required to retrieve this data.
I have code that asks a user to login already and gets an auth token which I can use to post a message to their facebook feed. Is there an additional step I need to do to be able to read their reviews/ratings?
Here is an example of the code to post to their feed/page.
response = Curl.post("https://graph.facebook.com/#{page_id}/feed", {
:message => message,
:access_token => auth_token
})
Thanks
If you're referring to Page Ratings (different from App Reviews!), then the endpoint is
GET /{page_id}/ratings
as described here: https://developers.facebook.com/docs/graph-api/reference/page/ratings You'll need a Page Access Token for this.
Where I get a little bit confused is that you mention that you want to
read their reviews/ratings
In that case it's something else, because afaik it's currently not possible to query the User's Page ratings via Graph API or FQL. It's was only possible to query App Reviews via FQL (see https://developers.facebook.com/docs/reference/fql/review/) (Update: FQL is no longer available since 2016)
You need to set permission in the app to access the {GET /{page_id}/ratings} API. The permission is common for
/page/comments,
/page/posts,
/page/ratings,
/page/tagged,
and the permission name is "pages_read_user_content"
https://developers.facebook.com/docs/permissions/reference/pages_read_user_content

How to get all facebook pages id associated with my account?

I want to get the statistics of all the pages associated with my account on facebook, i have the code to get the statistics of a page, i just want to get the page id of all the pages associated with my account, how can i do this?
Please help.
Thanks.
You'll need to request the manage_pages permission (more details here), once you have the aquired the permission, all you have to do is make a request to :
https://graph.facebook.com/YOUR_FACEBOOK_ID/accounts.
The return value will be a JSON with all the pages/applications that are associated with your account.
You can also use this great tool that facebook provides - The Graph API Explorer (/me/accounts) to explore what other information you can retrieve without having to write a single line of code :P very useful.
FB.api('/me/accounts', function(response) {
for (id in response.data)
{
page = data[id];
page.id;
page.name;
}
});
You can use Javascript API to do this, read more :http://developers.facebook.com/docs/reference/javascript/

Get public page statuses using Facebook Graph API without Access Token

I'm trying to use the Facebook Graph API to get the latest status from a public page, let's say http://www.facebook.com/microsoft
According to http://developers.facebook.com/tools/explorer/?method=GET&path=microsoft%2Fstatuses - I need an access token. As the Microsoft page is 'public', is this definitely the case? Is there no way for me to access these public status' without an access token?
If this is the case, how is the correct method of creating an access token for my website? I have an App ID, however all of the examples at http://developers.facebook.com/docs/authentication/ describe handling user login. I simply want to get the latest status update on the Microsoft page and display it on my site.
This is by design. Once it was possible to fetch the latest status from a public page without access token. That was changed in order to block unidentified anonymous access to the API. You can get an access token for the application (if you don't have a Facebook application set for your website - you should create it) with the following call using graph API:
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&
grant_type=client_credentials
This is called App Access Token. Then you proceed with the actual API call using the app access token from above.
hope this helps
You can use AppID and Secret key to get the public posts/feed of any page. This way you don't need to get the access-token. Call it like below.
https://graph.facebook.com/PAGE-ID/feed?access_token=APP-ID|APP-SECRET
And to get posts.
https://graph.facebook.com/PAGE-ID/posts?access_token=APP-ID|APP-SECRET
It's no more possible to use Facebook Graph API without access token for reading public page statuses, what is called Page Public Content Access in Facebook API permissions. Access token even is not enough. You have to use appsecret_proof along with the access token in order to validate that you are the legitimate user. https://developers.facebook.com/blog/post/v2/2018/12/10/verification-for-individual-developers/.
If you are individual developer, you have access to three pages of the data (limited), unless you own a business app.
You can get the posts by simply requesting the site that your browser would request and then extracting the posts from the HTML.
In NodeJS you can do it like this:
// npm i request cheerio request-promise-native
const rp = require('request-promise-native'); // requires installation of `request`
const cheerio = require('cheerio');
function GetFbPosts(pageUrl) {
const requestOptions = {
url: pageUrl,
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0'
}
};
return rp.get(requestOptions).then( postsHtml => {
const $ = cheerio.load(postsHtml);
const timeLinePostEls = $('.userContent').map((i,el)=>$(el)).get();
const posts = timeLinePostEls.map(post=>{
return {
message: post.html(),
created_at: post.parents('.userContentWrapper').find('.timestampContent').html()
}
});
return posts;
});
}
GetFbPosts('https://www.facebook.com/pg/officialstackoverflow/posts/').then(posts=>{
// Log all posts
for (const post of posts) {
console.log(post.created_at, post.message);
}
});
For more information and an example of how to retrieve more than 20 posts see: https://stackoverflow.com/a/54267937/2879085
I had a similar use case for some weeks and I used this API:
https://rapidapi.com/axesso/api/axesso-facebook-data-service/
I could fetch all posts and comments in some minutes, worked quite well for me.

Titanium.Facebook getting graph api access token

I'm developing an iPhone app with Appcelerator Titanium SDK 1.6.2
I am upload an photo to a users facebook album with the Titanium Facebook module, graph api.
The upload goes just fine and returns the items unique ID.
When I try to parse the JSON from the unique id I'm told i need to pass an access token, which makes sense.
How do I get the access token to be passed to the graph request url?
When I do a XHR GET request while passing Ti.Facebook.accessToken I get the following error
URL: https://graph.facebook.com/10150527948301195?access_token=t4CqzHallahfy4d7RnERrJb4ffOkQfJvrYrGEBoZ4so.epdiI6IjJGR2ZFY1ZTMHh6RlR6ZmNIcVctMHcifQ.NBRMth0vb7pXKcd8lHNz9aremoyNpvrbhz2P3zkgWJU4eHdfewOp1WruBNZS_lSDy0XM0Xu0ACry8aEmSckGJVQJxEioykrNZhT7S9mJG2OKWqMdk6ucg5IMhXMfndF9sdKwWrWb7uPKI57LzIOf5lvA
{
error = {
message = "Unsupported post request.";
type = GraphMethodException;
};
}
And if I don't pass Ti.Facebook.accessToken I'm asked for it.
I'm bound to be missing something, any help would be greatly appreciated.
see this link http://developer.appcelerator.com/blog/2011/02/facebook-module-changes-in-titanium-mobile-1-6-0.html
I think you should be using Titanium.Facebook.requestWithGraphPath(...)