using POST request on Facebook Graph API - facebook-graph-api

I want to access graph API to get the number of shares for different pages of my website. I can use the GET method to do so but I want to use POST so that I can send more url in a single request. The current implementation I have for GET is
http://graph.facebook.com/?ids=http://umairj.com/,http://umairj.com/146/how-to-clear-facebook-shares-cache/
Can anyone please help ?

This is badly documented (I mean I didn't find the information when I looked for it!), but there is way to pass all the parameters to the Graph API through POST method:
in your example, you should POST to http://graph.facebook.com/
with the following DATA:
ids=http://umairj.com/,http://umairj.com/146/how-to-clear-facebook-shares-cache/&method=GET
I'm not sure about the encoding of the POST DATA..in our case, we were just using ids=.....,.....,..... with numeric FB user ids and we didn't need to do any encoding, but you might need some url-encoding
Don't forget the &method=GET or it won't work ! It helped me break the url length limit that was causing bugs on Internet Explorer (I think RFC says 1024 characters, all browsers support much more, IE only ~4096 ) when we were passing too many ids through GET
if you wish to access non-public information, the same trick works with https://graph.facebook.com/ , provided you add &session_token=***** to your query

You can try to run a FQL query to get the stats for multiple urls. Facebook link_stat documentation has an example of how to do this. I'm pretty sure you can't POST to either the FQL query or the graph api you were using though unfortunately. Your FQL query would be:
SELECT url, share_count, like_count FROM link_stat WHERE url IN("http://umairj.com/","http://umairj.com/146/how-to-clear-facebook-shares-cache/")
Here is the url after properly url encoding the query: https://api.facebook.com/method/fql.query?query=SELECT+url%2C+share_count%2C+like_count+FROM+link_stat+WHERE+url+IN%28"http%3A%2F%2Fumairj.com%2F"%2C"http%3A%2F%2Fumairj.com%2F146%2Fhow-to-clear-facebook-shares-cache%2F"%29&format=json
Facebook provides a FQL testing tool to help.
Update: their API documention (see section titled "Delete) mentions you can do an HTTP POST to any of their methods and set the variable method to the method you want. You could try this, although this was designed for delete and put methods not available to javascript clients. It still looks like is all url based so I'm not sure it will take a form encoded parameter like you are looking to do.

I work at Facebook and I've updated our Graph API documentation to document this work around for very large requests:
https://developers.facebook.com/docs/graph-api/using-graph-api#largerequests

Related

How to get ondemand ids for Vimeo API

I am trying to work with the Vimeo API and I cannot figure out how to access the ondemand data.
The endpoint and parameters in the docs require an ondemand_id to work correctly. I assumed this ID would come from any official ondemand page within Vimeo. But whenever I search the ondemand pages of Vimeo and click on a resource, the URL does not contain any numerical ID.
It only contains the root path for the Vimeo website with /ondemand_page_name at the end. This value cannot be the ID since it is a string and not a number. I have looked through the entire page plenty of different times to try to find the ID but cannot seem to find it.
For example, when you visit a normal video page on Vimeo, the URL looks something like this:
https://vimeo.com/272976101
where the number 272976101 is the video_id that can be used within the API to get all the data about this particular video. Instead of this format, the ondemand pages have the format:
https://vimeo.com/ondemand/nebula
where there is no numerical ID within the URL. This is the issue I am having. How would I retrieve the public data about this ondemand page throught the API.
I feel like there may be a very simple solution/explanation to this issue and any help would be much appreciated.
Also, right now I am not using any SDK to access this data. I am strictly trying to figure out how the API works through the built-in client provided within the documentation.
It's undocumented, but you can use the On Demand custom url path as the ondemand_id.
So for your On Demand video at https://vimeo.com/ondemand/nebula, you can make an API request to this path: https://api.vimeo.com/ondemand/pages/nebula.
In the response, you'll see the "uri" value "/ondemand/pages/203314", which you can log on your end and use as the ondemand_id instead of /nebula.
Also note, this should be the same URL as your On Demand settings page: https://vimeo.com/ondemand/203314/settings
I hope this information helps!

How can i get all feeds from my profile using facebook graph api?

I am getting only limitted number of feeds i.e**(25 feeds**) from my facebook grapg api and is their any option to get more feeds and i mentioned limit=200 in my URL but i am getting only 25.URL is https://graph.facebook.com/v2.2/me/posts?access_token={access_token}&limit=200.Is their any way to get this please suggest me
First get an access token, then retrieve all your feed. Please note that you may need to reiterate the request as the returned content is paginated (that is, ['paging']['next'] element exists inside the answer).
See also the official documentation.

How To Get Historical "Facebook Page Likes" Data via Graph API or FQL

Was wondering if anyone knows how to get the historical data for any Facebook Page.
For example, number of fans for RedBull fan page on a given day in the past or for a given period that ends today so that I can show fan development of any page over a given period.
I tried it with the graph API and FQL (insights) but no luck.
https://graph.facebook.com/{USERNAME}/insights?fields=likes&period('week')&end_time_date('2011-06-26') --> empty result
Pulling the data via FQL also returns no results, plus it seems without a read_insights permission nothing is possible for page data
I'd need this to be available with only a generic user access token. This data is publicly available anyway. Result should be somewhat like this: http://www.socialbakers.com/facebook-pages/australia/
https://graph.facebook.com/{{pagename}}/insights/page_views?access_token={{access_token_key}}&since=1420070400&until=1421625600
Since & until parameter in the above code takes in unix time.
add necessary information in the {{ }} and this code should work.
Without insight permission I recommend that you write something to perform a nightly query on the page graph and record the stats you need. If the page is public most of the information shown on that site is available.
You could also scrape info from http://pagedata.appdata.com if the page has already been listed...

Facebook Page - Get Post feedback and impression via Graph API

I'm trying to get some insights on a list of Posts by a Page on Facebook.
To be specific, I want to get the information highlighted in this blog post via the API.
But I can't figure out how, anyone knows how?
As far as I know it's only possible using the "stream" table. So you've got to use FQL to query this data. Using this technique you'll only get the impressions directly. Feedback rate can be calculated by adding #comments and #likes and dividing the result by #impressions. Hope they'll add this to the insights graph api as well.
MartinHN
Refer to https://developers.facebook.com/docs/reference/api/#analytics
If you are trying to aggregate multiple pages or a page other than the requesting app then you may need grant read_insights permissions to your application.
Refer to http://developers.facebook.com/docs/reference/api/insights/

Parsing __utmz tracking cookie to get referral

I use Google Analytics on my site, and I want to read __umtz cookie to get referring link. I made some research and I wrote such code:
$refer=explode('utmcsr=',$_COOKIE['__utmz']);
if(count($refer)>1) $refer=explode('|',$refer[1]);
$refer=addslashes($refer[0]);
The problem is, this is not always working, sometimes I get junk as result. What I am doing wrong? Maybe someone have a good description of this cookie?
Check my Google Analytics Cookie Parser.
Google Analytics PHP Cookie Parser is a PHP Class that you can use to obtain data from GA cookies such as campaign, source, medium, etc. You can use this parser to get this data on your contact forms or CRM.
Just updated to version 1.2 with minor bugfixes and more info, number of pages viewed in current visit.
You could use $_SERVER['HTTP_REFERER'] to get the Referer.
Overall it is a bad idea to use other's people's cookies to get data unless you know exactly how they work, and when they update, or you use an API that THEY have made available.
Lets say the Google decides to revamp the cookie altogether so that the Referer information isn't available on the cookie, your system would break. It is best to get data directly from your own sources rather than someone else's.