I have this Url: http://herbalista.co/1r previously posted on my timeline with the Id = 1635826883323920
How to get that Id with FQL?
I have tryied this
https://graph.facebook.com/fql?q=SELECT+id+FROM+object_url+WHERE+url=%27http://herbalista.co/1r%27
and its return a different id = 1128761283806609
the post Id runs ok to embed a post but the returned Id doesn't works...
I'm using:
$posturl = "https://www.facebook.com/herbalistas/posts/".$id;
<div class="fb-post" data-href="$posturl" data-width="400"><div class="fb-xfbml-parse-ignore"><blockquote cite="$shortened"><p></p></blockquote></div></div>
I think that the returned Id is global for the link but not the original Id from the original post on my timeline
I find the solution:
https://graph.facebook.com/fql?q=SELECT+link_id+FROM+link+WHERE+owner=[USER_ID]+AND+url=%27[URL]%27LIMIT%201000&access_token=[FULL-USER-ACCESS-TOKEN]
it fetch all posts on user timeline and filter it by url
Related
I am using Facebook realtime api, as I get only the updates and have to fetch the whole data by hitting the server again.
I have a page, my app added to that hence I am getting page feed(like, comment, post, all).
When any user posts on the page, we get the update from Facebook realtime update api. But when I try to fetch post data using the Koala gem it gives me error, note that error is not in case of Update from Page itself(page admin) but when some other user posts on it.
Following is the code for help :-
Trying to fetch using long lived page-token, and without that too, failing both ways
##graph = Koala::Facebook::API.new ACCESS_TOKENS["facebook"]["page_token"]
##public_graph = Koala::Facebook::API.new
JSON response from facebook :-
{"object"=>"page",
"entry"=>
[{"id"=>"123412341234234",
"time"=>1412341234,
"changes"=>
[{"field"=>"feed",
"value"=>
{"item"=>"post",
"verb"=>"add",
"post_id"=>123412341234123,
"sender_id"=>1234123412}}]}]}}
##public_graph.get_object("123412341234123")
*** Koala::Facebook::ClientError Exception: type: GraphMethodException, code: 100, message: Unsupported get request. [HTTP 400]
##graph.get_object("123412341234123")
*** Koala::Facebook::ClientError Exception: type: GraphMethodException, code: 100, message: Unsupported get request. [HTTP 400]
Please help me out to understand how to fetch the public post data using the post_id provided by the realtime-updates api of facebook.
Q: how to fetch the public post data using the post_id provided by the realtime-updates api of facebook.
For fetching public data of the post from the page, you will need to specify both the IDs (page id as well as post id) you are getting in the RT hit form fb.
You will need to pass id as <page_id>_<post_id>. In your case, it will be:
rt_hit = {"object"=>"page",
"entry"=>
[{"id"=>"123412341234234",
"time"=>1412341234,
"changes"=>
[{"field"=>"feed",
"value"=>
{"item"=>"post",
"verb"=>"add",
"post_id"=>123412341234123,
"sender_id"=>1234123412}}]}]}}
entry = rt_hit["entry"].first // you may want to have loop instead of `first`
public_id = "#{entry['id']}_#{entry['changes'].first['value']['post_id']}"
##public_graph.get_object(public_id) // fetch object
Im trying to return the friend list with uid of an authenticated user. however I only get a partial return value, some part of the friends are just left out:
graph = Koala::Facebook::API.new(fb_token)
friends = graph.get_connections("me", "friends")
#some friend action
when I type in the
friends.paging["next"]
in the browser it also returns an empty json array
"data": [ ]
How am I doing it wrong and what is the correct practice?
You need to get the permission 'user_friends' to get friendlist, otherwise you'll receive a empty data:
The field 'friends' is only accessible on the User object after the user grants the 'user_friends' permission.
Try yourself:
https://developers.facebook.com/tools/explorer?method=GET&path=me%2Ffriends&version=v2.5
So, with correct permission you can do:
graph = Koala::Facebook::API.new(fb_token)
result = graph.get_connections('me', 'friends')
to paginate:
next_page = result.next_page
LAST BUT NOT LEAST:
Only friends who installed this app are returned in API v2.0 and
higher. total_count in summary represents the total number of friends,
including those who haven't installed the app.Learn More
You just try this..
This is very simple to you can get all friend count in a single line :)
#graph = Koala::Facebook::API.new(facebook_token)
#friends = #graph.get_connection("me", "friends",api_version:"v2.0").raw_response["summary"]["total_count"]
It is said, that it is not possible to initiate new conversation through the API alone, except using Facebook's own Form integrated in the app. Is this correct, or is there some new API, which enables me to initiate a new conversation?
To reply to an existing conversation, I retrieved the conversations id using the following FQL Query "SELECT thread_id, . WHERE viewer_id={0} AND folder_id=0". Afterwards I retrieved the PageAccessToken for my app page using my user Access token, and tried to use this call:
*You can reply to a user's message by issuing an HTTP POST to /CONVERSATION_ID/messages with the following parameters [conversation id, message]. A conversation ID look like t_id.216477638451347.*
My POST Call looked like this (this is not a valid thread id): /t_id.2319203912/messages with message parameter filled. But it always said "Unknown method". Can you help me out with this one? Is there a parameter missing? I passed in the page's Access Token to call this one.
Is there some API out (except Facebook's Chat API), that I am missing, which can send private messages to users?
Edit:
What I wonder about is, that the code below only returns a single page, the application's page. Is this correct, or is there another page token required? This is what bugged me the most about the returned page.
The FacebookClient uses my UserToken to perform the next following task.
This is the code to retrieve my Page Access Token:
dynamic pageService = FacebookContext.FacebookClient.GetTaskAsync("/"+UserId+"/accounts").Result;
dynamic pageResult = pageService.data[0];
_pageId = pageResult["id"].ToString();
return pageResult["access_token"].ToString();
Now the code to retrieve my ConversationÍd:
dynamic parameters = new ExpandoObject();
parameters.q = string.Format("SELECT thread_id, folder_id, subject, recipients, updated_time, parent_message_id, parent_thread_id, message_count, snippet, snippet_author, object_id, unread, viewer_id FROM thread WHERE viewer_id={0} AND folder_id=0", FacebookContext.UserId);
dynamic conversations = FacebookContext.FacebookClient.GetTaskAsync("/fql",parameters).Result;
The following code is executed using the access token retrieved from the code above (page access token request).
Now the Code used to send the reply:
dynamic parameters = new ExpandoObject();
parameters.message = CurrentAnswer;
string taskString = "/t_id." + _conversationId + "/messages";
dynamic result = FacebookContext.FacebookClient.PostTaskAsync(taskString,parameters).Result;
return true;
I also tried it with facebook's graph API Debugger using the token, which is returned by my first part of code. But with the same error message.
I am using Facebook comment box plugin:
<fb:comments href="${myPageUrl}" num_posts="20" width="630"></fb:comments>
Every thing is working fine. The problem is that I want to store the comment posted into my database. Is there any way to fetch the text posted on the comment box.
I am using the following js to catch comment-create event.
FB.Event.subscribe('comment.create', function(response) {
alert(response.commentID)
});
I'm getting some commentId from this but I don't know how to fetch the exact comment posted on a particular comment-create event.
Coomie: Actually whenever a comment is posted, I catch the event thru 'comment.create'. I was able to catch the event but I was wondering how to get the comment(text) posted at that particular event. Like event.text or event.comment but there was no direct method found
So, now I am manipulating it with fql. Which is somewhat similar to you example. First retrieving the whole list and then selecting the top one.
My sample code is below:
FB.Event.subscribe('comment.create', function(response) {
FB.api({
method: 'fql.query',
query: "SELECT post_fbid, fromid, object_id, text, time from comment WHERE object_id in (select comments_fbid from link_stat where url ='${PageUrl}') order by time desc limit 1"
},
function(response) {
var feed = response[0];
alert(feed.text)
});
});
So this method is giving me exactly the same result I want.
I don't have the complete answer but this should get you on your way.
You can use the facebook graph api to extract information about an open graph id (an open graph id is FB's way of identifying a person, website, application or URL). Eg. this page:
http://www.inhousegroup.com.au/newsroom/23-best-practice-for-advanced-seo/ (the place that fired me)
uses a comment box. The web page has an open id of 10150441190653416. So when you comment on this page facebook sees your comment as a wall post on that page's "wall".
Using the graph api, you can get some JSON info about the page here:
http:/graph.facebook.com/10150441190653416
And you can get the posts from this address:
http://graph.facebook.com/10150441190653416/posts
But you'll have to get an access token.
Then you just have to import the posts on save and compare your db to the JSON and add records as neccessary.
Good luck!
FB.Event.subscribe('comment.create', function(response) {
var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
FB.Data.waitOn([commentQuery], function () {
text = commentQuery.value[0].text;
// Use your preferred way to inform the server to save comment
$.post( 'http://example.com/comment', text )
});
});
I'm writing an application that uploads a photo to facebook. I'm not supplying an album ID so an album is created on behalf of my app.
My question is: how do I get the album ID the photo was uploaded to?
When I GET the the photo information the album isn't present in the JSON which was my hope.
Jimmy Sawczuk's answer is close, but doesn't work because FQL Photo table columns aid and pid are Rest/FQL API ids, not Graph API ids.
Fortunately the object_id and album_object_id columns in this table are indexable (contrary to the documentation) so this should give you both Rest/FQL & Graph ids for the album:
select aid, album_object_id from photo where object_id = ${GRAPH_PHOTO_ID}
In general object_id fields in Rest/FQL API responses are Graph API id (except for photo notifications, where it's the Rest/FQL id).
Re HonkyHonk's answer: not all photo link urls have a set parameter; in this case I think you can find the Rest/FQL API photo id from its other parameters, and then use Rest/FQL API to get the album id:
For users with 32-bit user-ids: calculate (id << 32) | pid
eg for http://www.facebook.com/photo.php?pid=7518353&id=549683637 this gives 2360873244068853905
Otherwise concatenate id, _ and pid
eg for http://www.facebook.com/photo.php?pid=155052&id=100002937903251 this gives 100002937903251_155052
It would help a lot if Facebook could document something about the two types of ids. Also the Graph API Photo schema should include the album's Graph API id.
This is the easy way to get it :
This issue has been bugging me for a while as well, but I think I have cracked the nut.
The album ID is hidden in the link value, so if you have a photo-post object from the Graph API, you can retrieve the Album ID like this:
NSString *link = [item valueForKey:#"link"];
NSString *album_id = nil;
NSRange fRange = [link rangeOfString:#"set=a."];
if(fRange.location != NSNotFound) {
NSInteger firstPos = fRange.location + 6;
NSInteger endPos = [link rangeOfString:#"." options:NSLiteralSearch range:NSMakeRange(firstPos, 25)].location;
album_id = [[link substringWithRange:NSMakeRange(firstPos, endPos - firstPos)] copy];
}
It could probably all be stripped down to one line of code, but I think this is more readable.
For getting the album information use:
[facebook requestWithGraphPath:album_id andDelegate:delegate];
For getting all the photos in an album use:
[facebook requestWithGraphPath:[NSString stringWithFormat:#"%#/photos", album_id] andDelegate:delegate];
Hope this can help someone.
If I'm understanding you correctly, you have the photo ID but need the album ID. You could try using the photo FQL table with the following query:
SELECT aid, pid FROM photo WHERE pid = '<your photo id>'
Long, clunky, but theoretically valid way:
http://graph.facebook.com/userid/albumswill get you a list of all the albums the user lets you see, then you can search the album objects (api here) for created_times that match the time you created the album, which you can store when you create the album.
This is almost certainly a horrible way to do it, but it should work.
Richard Barnett's solution works well for me, I use this as an FQL query through the Graph API to get a JSON response like I would for any other Graph API query:
https://graph.facebook.com/fql?q=select+album_object_id+FROM+photo+WHERE+object_id='[PHOTOID]'
This returns:
{
"data": [
{
"album_object_id": "10150531092908837"
}
]
}
Then you can access the album ID using:
<?php
$strPhotoAlbumID = $objFacebookAPI->data[0]->album_object_id;
?>
This is the cleanest solution i've found as Facebook constantly change the format of their photo and album URLs so parsing these with RegEx wont work as a long term fix.
I ended up just using the legacy REST api since the album ID is passed with the link to the image in the server response. I then used a regex to pull the id out.
Not the best solution and I wouldn't recommend it but I feel its better than adding another several server requests to the code.
function get_album_id_by_album_name($album_name){//return array of data
$fql = 'SELECT aid, owner, name, object_id FROM album WHERE owner=me() and name="'.$album_name.'"';
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $this->facebook->api($param);
return $fqlResult;
}
String albumID = "https://www.facebook.com/photo.php?fbid=192570127478130&set=a.135556629846147.24342.100001754323389&type=1";
albumID = albumID.split("&set=a.")[1];
albumID = albumID.split("\\.")[0];
System.out.println(albumID);