getting facebook comment by comment id - php

I am trying to get details of a comment by its comment id. This comments exists in a facebook comments box plugin which I have used in a website.
I tried the facebook api explorer and using this as the input
1388155601440738?fields=id,from,created_time
I got the response I wanted
{
"id": "1388155601440738",
"from": {
"name": "Ahmed Anas",
"id": "599062201"
},
"created_time": "2014-01-06T08:12:25+0000"
}
Unfortunately I cant figure out how to implement this in php..
I would assume all I need to do was get the contents from
http://graph.facebook.com/1388155601440738?fields=id,from,created_time
but I get an Unsupported get request exception
I also tried the php API with this code but no luck
$response = $facebook->api(1388155601440738);
$response = $facebook->api('/1388155601440738?fields=id,from,created_time');

I believe the comment id you are passing is incorrect. Also you have to add /comments after comment id. So the final URL for you would be something like http://graph.facebook.com/750281525001535/comments?fields=id,from,created_time. This one works fine

Related

Facebook Graph API Individual Posts fields

I am using this solution to select an individual post from a user's feed.
I am using PHP Facebook SDK on the latest version 5.7.
Previously this had worked with no problem, I made my request like:
$response = $this->fb->get(
'/'.$user['id']. '_' .$post_id.'/?fields=id,description,name,full_picture',
$this->get_access_token()
);
And I would get all the fields. However, over the last few months, this has stopped working.
The access_token requests the following permissions:
['user_events', 'user_posts']
I can't find any documentation on the solution outlined in the Stack Overflow post. So I am not sure if I need any more permissions.
I do not get an error when sending this request, I just get the ID back and nothing else. This can be confirmed in the Graph API Explorer:
The v5.0 docs show that when requesting a post I can get full_picture, name and description without mentioning any additional permissions required.
However that same page recommends making the request with just the post ID:
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/{post-id}',
'{access-token}'
);
}
Which does not work, you
{
"error": {
"message": "(#12) singular statuses API is deprecated for versions v2.4 and higher",
"type": "OAuthException",
"code": 12,
"fbtrace_id": "ACs2rpwobcW8zSFyL_0Q2yQ"
}
}
The error does mention statuses and not posts but I am not sure how to distinguish the difference between those, I figured they were the same.
Has anyone else stumbled across this and found a solution?
It turns out that the fact it was called status was important. I made a request to the users feed, and noticed that some older posts were returning the data that I needed. I had a look through the list of fields and appended message and type to get the following response:
Not very well documented I guess. But got there in the end, hopefully this can help someone else in future.

get facebook post id from url link

I try to get a post id from an url in the graph explorer
for example I try to get the ID of this post in graph explorer
this is the url
http://www.imdb.com/gallery/rg1859820288/mediaviewer/rm1167930112
And on Facebook this is the post
https://www.facebook.com/imdb/posts/10155250004608949
So the ID of the post is 10155250004608949
When I try to put my link on the graph explorer
It return me
{
"og_object": {
"id": "1460657060613493",
"description": "Untitled Jurassic World Sequel (2018)",
"title": "Latest Stills",
"type": "article",
"updated_time": "2017-03-08T22:45:48+0000"
},
"share": {
"comment_count": 0,
"share_count": 16
},
"id": "http://www.imdb.com/gallery/rg1859820288/mediaviewer/rm1167930112"
}
I don't know what it is this id : 1460657060613493
So I don't know if it is possible to get the post id like that
I don't know what it is this id : 1460657060613493
That is the id of the Open Graph object that the URL http://www.imdb.com/gallery/rg1859820288/mediaviewer/rm1167930112 represents.
So I don't know if it is possible to get the post id like that
Of course it is not possible to get the post id via the IMDB URL, because “the” post id does simply not exist - multiple users and pages could have shared that IMDB URL.

Facebook graph API for videos not returning expected data

https://graph.facebook.com/v2.6/{video_id}/video_insights?metric=total_video_views&access_token={token}
I am using above link to get JSON details in PHP for a video object, however i am not able to get the required data w.r.t. the provided metric
data required : total_video_views
here is the FB for metric:
https://developers.facebook.com/docs/graph-api/reference/video/video_insights/
when i use
?metric=total_video_views
FB graph api gives
{
"data": [
],
"paging": {
"previous": "https://graph.facebook.com/v2.6/1034830076599589/video_insights?access_token=EAACEdEose0cBABRiFOqQuZBZBaKTZBW89XcMrTjakJseF76YjL2Hfj1rBRES2FAztFNMQWsMVdv9zwO90ISjx8efBVdfLZCyZBnHzDF5pTLNTgJPIH6PcBnb1YAD5XCWyvK6HIz3rHNP3xs3DfODSbUZCKZC2GkbkzYj7goFgfWVAZDZD&debug=all&format=json&method=get&metric=total_video_views&pretty=0&suppress_http_code=1&since=-86400&until=0",
"next": "https://graph.facebook.com/v2.6/1034830076599589/video_insights?access_token=EAACEdEose0cBABRiFOqQuZBZBaKTZBW89XcMrTjakJseF76YjL2Hfj1rBRES2FAztFNMQWsMVdv9zwO90ISjx8efBVdfLZCyZBnHzDF5pTLNTgJPIH6PcBnb1YAD5XCWyvK6HIz3rHNP3xs3DfODSbUZCKZC2GkbkzYj7goFgfWVAZDZD&debug=all&format=json&method=get&metric=total_video_views&pretty=0&suppress_http_code=1&since=0&until=86400"
}
}
but there is no field regarding the required metric i.e. total_video_views
am i making here some wrong request or something else ?
https://graph.facebook.com/v2.6/{video_id}/video_insights/total_video_views&access_token={token}
Should work for you.

How can I automatically scrape new information from page with Facebook open graph API

Hi I have this problem with Facebook open graph API.
I know I can manually scrape new information about meta tags from a page with https://developers.facebook.com/tools/debug/. But I'm trying to use api to do it automatically, but I just can't understand what is going on.
I stumbled across this https://developers.facebook.com/tools/explorer/145634995501895/. Can you guys tell me exactly what to type there to scrape new og meta tags?
For page: http://www.akademiaharmonia.pl/o-jodze.html
What I tried: in this Graph API Explorer I chose "POST" and added 2 fields:
id = http://www.akademiaharmonia.pl/o-jodze.html
scrape = true
I got this error:
{
"error": {
"message": "An access token is required to request this resource.",
"type": "OAuthException",
"code": 104
}
}
I don't really understand why but it works perfectly fine now. I also noticed that the graph explorer is now 2.1 instead of 2.0... hmm...

retrieve linkedin profile url from php api

I am using the Simple LinkedIn PHP Library to create a searching feature for an application. The user can search through LinkedIn and retrieve matched users information. As of right now the feature is working properly, but how can I parse the XML returned by the API and get the user's ID to create a link to their profile?
This is a sample of the array returned by the API call:
{
"numResults": 17325,
"people": {
"_count": 10,
"_start": 0,
"_total": 110,
"values": [
{
"firstName": "Leon",
"headline": "Digital Marketing | Mobile Marketing | Video Marketing | SEO/SEM | Digital Media Sales Trainer",
"id": "EFMHqoTad3",
"lastName": "E. Spencer",
"pictureUrl": "http://m3.licdn.com/mpr/mprx/0_jOgiHrinvW_afCa6PRDyHPXZBdvfi3a6xyWyHPXke7T0p5JQl4SfQ1KEMXzr86fopjxjFqnEf1I-"
},
If I understand correctly, a users profile url looks like http://www.linkedin.com/profile/view?id=156996610 so I should just be able to extract the ID from the API call and append to the view?id= query right? Can I do this with the SimpleXML PHP Library?
By XML I believe you mean JSON.
One way in php is by using the json_decode() function.
$url = file_get_contents("http://www.linkedin.com/profile/view?id=156996610");
$json =json_decode($url,true);
the second value "true" means it will be returned as an associative array.
Then you can access whatever you want from that response.
I.E a user ID..
$userID = $json['people']['values']['id'];
I suggest reading the json_decode() documentation to understand how this works.

Categories