I am trying to Implement Facebook comments api(See this question if you got time), I need to get an Object id, all what I have is Object URL. If I will use Facebook debug, they are giving me some thing like this:
Graph API: http://graph.facebook.com/451006711598242
I believe that 451006711598242 is my id. I been trying to do the fallow calls:
https://graph.facebook.com/comments?id={myUrl} but it's not working. Any ideas what I need to do?
Try this to return the object_id:
$object_url = 'http://google.com';
$url = 'SELECT url, id, type, site FROM object_url WHERE url = "'.$object_url.'"';
$fql_query_url = 'https://graph.facebook.com/fql?q='.urlencode($url);
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
$object_id = $fql_query_obj['data'][0]['id'];
Related
I would like to fetch a user's email using the C# Facebook SDK. How can I do so? I've tried the code below, but I just get an empty email. Is it because I somehow need to ask for more rights? If so, how do I do that?
Facebook.FacebookClient fbc = new Facebook.FacebookClient(user.MobileServiceAuthenticationToken);
dynamic clientCredentials = await fbc.GetTaskAsync("oauth/access_token",
new{client_id = facebookClientId,client_secret = facebookClientSecret,
grant_type = "client_credentials",redirect_uri = "https://xxx.azure-mobile.net/signin-facebook"});
fbc.AccessToken = clientCredentials.access_token;
fbc.AppId = facebookClientId;
fbc.AppSecret = facebookClientSecret;
string id = user.UserId.Replace("Facebook:", string.Empty);
dynamic result = await fbc.GetTaskAsync(id + "?fields=id,name,picture,last_name,first_name,gender");
Best regards
TJ78
You need to gather the email permission in the login Url's scope parameter, otherwise you will not be able to receive the email field.
So I tried to post on my friends wall using the following code:
var fb = new FacebookClient(_accessToken);
dynamic parameters = new ExpandoObject();
parameters.message = "Google is your friend";
parameters.link = "http://gidf.de/";
parameters.Name = "Test";
parameters.from = new { id = "100000", name = "me" };
parameters.to = new { id = "1000001", name = "friend" };
dynamic result = fb.Post("1000001/feed", parameters);
However, I get told that my application does not support this. I did some googling work, and read that [USER_ID]/feed is deprecated and that I have to invoke the feed dialog to ask the user to publish it. How would I go on doing this with the C# SDK?
As of February 6, 2013, you can't post to Friends Timeline on behalf of the user.
Read Here: https://developers.facebook.com/roadmap/completed-changes/
Client-Side you can use the FB.ui method to pop up the feed dialog.
Here's an example: https://stackoverflow.com/a/15426243/1405120
Server-Side, you can use the URL Redirection.
https://www.facebook.com/dialog/feed?
app_id=458358780877780
&link=https://developers.facebook.com/docs/reference/dialogs/
&redirect_uri=https://mighty-lowlands-6381.herokuapp.com/
Read more about Feed dialog here, https://developers.facebook.com/docs/reference/dialogs/feed/
I write application in Lua with Corona SDK. I want to post some unique text with Facebook feed dialog. My code is:
facebook.showDialog( "feed", {message = "This is my unique text" } )
I tried also:
local text_arr = {}
text_arr.text = "This is my unique text"
facebook.showDialog( "feed", {properties = text_arr } )
Both of them don't work. I don't see the "This is my unique" string on my wall after dialog publish action.
So , how can I do it? Thanks
After the user logs in to facebook, which you need to do with:
facebook.login( appId, listener )
You can now send requests to the facebook graph API using request function:
facebook.request( "me/feed", "POST", {message = "Hello Facebook"} )
You can check the documentation page here http://docs.coronalabs.com/api/library/facebook/request.html
If you really want to use the dialog, which I have never tried, I suppose you have to define some more parameters:
From what I can understand from http://docs.coronalabs.com/api/library/facebook/showDialog.html and https://developers.facebook.com/docs/reference/dialogs/ it should turn out to be something like this:
facebook.showDialog( "feed", {
redirect_uri = "YOUR_URL",
link = "YOUR_LINK",
picture = "YOUR_PICTURE_URL",
name = "DIALOG_NAME",
caption = "DIALOG_CAPTION",
description = "DIALOG_DESCRIPTION"
})
Some properties are probably optional, so mess around with it a bit...
I have seen this question but what I want is different.
I want to get the Facebook ID not from a general URL (and therefore conditional if it has Like button or not). I want to get the Facebook ID given a Facebook page using the Graph API.
Notice that Facebook pages can have several formats, such as:
http://www.facebook.com/my_page_name
http://www.facebook.com/pages/my_page_name
http://www.facebook.com/my_page_ID
I know I could do some regex to get either the my_page name or my_page_ID, but I am wondering if any one know if GraphAPI is supporting what I want.
It seems to me that the easiest solution to what you describe is to just get the id/name from the url you have using lastIndexOf("/") (which most languages have an equivalent for) and then get "https://graph.facebook.com/" + id.
The data that this url returns has the id (i.e.: 6708787004) and the username (i.e.: southpark), so regardless of which identifier you use (what you extract from the url using lastIndexOf), you should get the same result.
Edit
This code:
identifier = url.substring(url.lastIndexOf("/"))
graphUrl = "https://graph.facebook.com/" + identifier
urlJsonData = getGraphData(graphUrl)
Should work the same (that is result with the same data) for both:
url = http://www.facebook.com/southpark
And
url = http://www.facebook.com/6708787004
(you'll obviously need to implement the getGraphData method).
Also, the 2nd url form in the question is not a valid url for pages, at least not from my tests, I get:
You may have clicked an expired link or mistyped the address. Some web
addresses are case sensitive.
The answer to the question is posted above but the method shown below works fine we do not have to perform the regex on the facebook page urls
I got the answer by this method
FB.api('/any_fb_page_url', function(response){
console.log(response);
});
any_fb_page_url can be any of the following types
https://www.facebook.com/my_page_name
https://www.facebook.com/pages/my_page_name
https://www.facebook.com/my_page_ID
This are also listed in question above
This code is tested on JS console available on Facebook Developers site tools
You can get the page id by using the below api
https://graph.facebook.com/v2.7/smhackapp?fields=id,name,fan_count,picture,is_verified&access_token=access_token&format=json
Reference image
This answer is updated and checked in 2019:
and it is very simple because you do not need to extract anything from the link. for examples:
https://www.facebook.com/pg/Vaireo-Shop-2138395226250622/about/
https://www.facebook.com/withminta
https://www.facebook.com/2138395226250622
https://graph.facebook.com/?id=link&access_token=xxxxxxxx
response:
{
"name": "Vaireo Shop",
"id": "2138395226250622"
}
full nodeJS answer:
async function getBusinessFromFBByPageURL(pageURL: string) {
const accessToken = process.env.fb_app_access_token;
const graphUrl = `https://graph.facebook.com/?id=${pageURL}? access_token=${accessToken}`;
const fbGraphResponse = await Axios.get(graphUrl);
<?php
function getFacebookId($url) {
$id = substr(strrchr($url,'/'),1);
$json = file_get_contents('http://graph.facebook.com/'.$id);
$json = json_decode($json);
return $json->id;
}
echo getFacebookId($_GET['url']);
?>
Thats a PHP example of how to get the ID.
As of Nov 26 2021 none of these solutions work.
Facebook has locked down the API so you need an App Review.
https://developers.facebook.com/docs/pages/overview/permissions-features#features
This answer takes into account that a URL can end with a trailing slash, something that Facebook event pages seem to have in their URLs now.
function getId(url) {
var path = new URL(url).pathname;
var parts = path.split('/');
parts = parts.filter(function(part) {
return part.length !== 0;
});
return parts[parts.length - 1];
}
You can Use Requests and re Modules in python
Code:
import requests,re
profile_url = "https://www.facebook.com/alanwalker97"
idre = re.complie('"entity_id":"([0-9]+)"')
con = requests.get(profile_url).content
id = idre.findall(con)
print("\n[*] ID: "+id[0])
Output:
[*] ID: 100001013078780
Perhaps you can look through the https://developers.facebook.com/docs/reference/api/#searching docs: search against a couple of types and if you find what you're looking for go from there.
I want to delete the post as page.
I already have access token of the admin user and access token from the page.
My Code:
var fbClient = new FacebookClient { AccessToken = getPageAccessToken() };
dynamic parameters = new ExpandoObject();
parameters.id = postId;
fbClient.Delete(m_GroupId + "/feed",parameters);
I get the following error:
{"error":
{
"type":"OAuthException",
"message":"Invalid token: \"PAGE_ID\". An ID has already been specified."
}
}
I replaced the page id above with PAGE_ID
use the page access token and pass the post id as the path for Delete method.
var fb = new FacebookClient("pageAccessToken");
fb.Delete(postId);
I don't know the C# SDK, but from the look of it you're setting the ID twice, once with parameters.id and again with m_GroupID