Sometimes I get burst of visitors from Facebook, which I am curious to know where exactly on Facebook if the page is public, of course!
Is there a way to decode and track back Facebook referral URL to actual page in the Facebook?
URL format is the following:
http://www.facebook.com/l.php?u=http%3A%2F%2Fwww.domain.com%2F&h=iAQDjUC4AQHjQeIXcOi8z9jamgyDk8vpuylpdaRT3aHu6Q&s=1
From mobile it is shorter:
http://m.facebook.com/l.php?u=http%3A%2F%2Fwww.domain.com%2F&h=BAQFX067m&s=1
Where domain.com is my website for example.
You can extract the URL manually using substr and then apply decodeURIComponent:
function extractFacebookUrl(u) {
u = u.substr(u.indexOf('l.php?u=') + 8); // remove before ?u=
u = u.substr(0, u.indexOf('&')); // remove after &
return decodeURIComponent(u);
}
var link = "http://www.facebook.com/l.php?u=http%3A%2F%2Fwww.domain.com%2F&h=iAQDjUC4AQHjQeIXcOi8z9jamgyDk8vpuylpdaRT3aHu6Q&s=1";
var linkMobile = "http://m.facebook.com/l.php?u=http%3A%2F%2Fwww.domain.com%2F&h=BAQFX067m&s=1";
document.body.innerHTML = extractFacebookUrl(link) + "<br/>" + extractFacebookUrl(linkMobile);
Related
When I access Facebook through the Graph API I get only very few entries. For instance if I access the Galaxy S4 fan page through the Graph API I see only four entries:
https://graph.facebook.com/412437702197294/comments/
if I access it through restFB I only get 2:
FacebookClient publicOnlyFacebookClient = new DefaultFacebookClient();
Page page = publicOnlyFacebookClient.fetchObject("GalaxySFour", Page.class);
JsonObject galaxySFourID = publicOnlyFacebookClient.fetchObject("GalaxySFOUR", JsonObject.class);
JsonObject galaxySFour = publicOnlyFacebookClient.fetchObject(galaxySFourID.getString("cover_id") + "/comments", JsonObject.class);
Vector<String> comments = new Vector<String>();
for(int i = 0; i < galaxySFour.length(); i++) {
comments.add("Message: " + galaxySFour.getJsonArray("data").getJsonObject(i).getString("created_time") + ": " + galaxySFour.getJsonArray("data").getJsonObject(i).getString("message"));
}
I'm aware that I cannot get all data, but I didn't expect to get so little. Is there anyway to get more data?
Access via this link : http://facebook.com/412437702197294,
there are only 4 comments. So, https://graph.facebook.com/412437702197294/comments/ return 4 comments is right.
By default, when retrieving data via Facebook Graph API, you only get 20 results.
You can use limit to get more data, such as:
http://facebook.com/412437702197294?limit=500
The maximum limit is 5000.
I want to manually add RSS feed URL in my iPhone App. Is there any way to validate RSS feed. I know that proper validation of URL can be done, but there any way to find out whether given url contains proper RSS/atom?
First you can verify as weather it is valid URL or not. and after it you can verify array count fromt your response. Because, if it is not valid URL, then you will not get any data from response..
Taken from http://www.haiders.net/post/C-RSS-Feed-Fetcher-Display-RSS-Feed-with-2-lines-of-Code.aspx
//www.haiders.net | Jan 2010
//C# Example: Fetch and Shape RSS Feed
string rssUri = "http://some.feed.uri.xml";
var doc = System.Xml.Linq.XDocument.Load(rssUri);
var rssFeed = from el in doc.Elements("rss").Elements("channel").Elements("item")
select new { Title = el.Element("title").Value, Link = el.Element("link").Value,
Description = el.Element("description").Value };
//The data is ready, assuming we have a ListView to display the Feed named lvFeed
//Lets bind the Feed to the ListView
lvFeed.DataSource = rssFeed;
lvFeed.DataBind();
//Thats all!
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'm absolutely new to programming and just managed to learn the basics of ActionScript 3. Now, I would like to learn how to post on my Friends' Walls via the as3 SDK using the UI class (taken from a nice Tutorial):
This is how I post on my own Wall:
protected function newsFeed ():void
{
// define your caption text
var theCaption:String = "CaptionText";
// define the descrition text
var theDescription:String = "Text for game Achievement";
// We need to follow the FB docs to tell it what sort of input we are sending to FB
// We are trying to set the 'feed'
var methodInput:String = 'feed';
var thePicture:String = "mylink/picture.png";
var theLink:String = "mylink";
var theName:String = "Name of FB Status Setter";
// Create an object that we'll call 'data' and fill it with the actual data we're sending to Facebook
var data:Object = {
caption:theCaption,
description:theDescription,
picture:thePicture,
name:theName,
link:theLink
};
Facebook.ui(methodInput, data, onUICallback);
}
protected function onUICallback(result:Object):void
{
// do something
}
This works perfectly fine. I know that I have to integrate the parameter "to" somewhere. But I don't know where and how. Sorry I'm very very new to this. This is from Facebook Docs
Properties
from: The ID or username of the user posting the message. If this is unspecified, it defaults to the current user. If specified, it must be the ID of the user or of a page >that the user administers.
to: The ID or username of the profile that this story will be published to. If this >is unspecified, it defaults to the the value of from.
Hopefully someone can help me out.
Best Regards,
Amir
P.S.: Is there a way to post only one friend's wall and another way to post on several friends' walls?
I believe you want to use Facebook.api() rather than 'ui'. According to the documentation for the AS3 FB API, 'ui' just opens the share dialog. If you want to create a post on a friends wall, then you'll want to use 'api'.
I haven't tested this in Flash, but I think you can set the method as /PROFILE_ID/feed ... of course replacing "PROFILE_ID" with the FB uid of the friend. Then, include the arguments; message, picture, link, name, caption, description and source in your data object.
So your code would look something like:
var method:String = "/friend_id/feed";
var data:Object = {};
data.message = "Your message";
data.picture = "http://www.google.com/kittens.jpg";
data.link = "http://www.mysite.com/link";
data.caption = "Your caption";
data.description = "Your description";
data.source = "http://www.mysite.com/video.swf";//(optional) source is a video or Flash SWF
Facebook.api(method, yourCallback, data, "POST");
function yourCallback(result:Object, fail:Object):void {
if (result) {
trace(result)
} else if (fail) {
trace(fail);
}
}
If you have multiple friends, you could probably just put the uid's in an array and loop through the method above. The AS3 API has a batch request method that I haven't tried, but you can check out the Documentation.
Facebook has some pretty helpful tools that are somewhat hidden.
Checkout their Debugger and their Graph API Explorer
Hope that's helpful.
I am working with the Graph API but I have found it to be rather limited. In the news feed on the Facebook website you might see "X and 14 other friends likes Y page." or "X and 3 other friends has changed their profile picture."
In the Graph API it will look like the code below when X and 14 other friends has liked the same page. The Graph API only returns the name of X but not how many friends other than X who have liked the page.
{
application = {
id = 01010101;
name = Pages;
};
comments = {
count = 0;
};
"created_time" = "2011-08-15T08:35:47+0000";
description = "Description of page.";
from = {
id = 1111;
name = "X";
};
icon = "---";
id = "http://static.ak.fbcdn.net/rsrc.php/v1/yN/r/xC785tTCIQO.gif";
link = "http://..../";
name = "Y";
picture = "---";
type = link;
"updated_time" = "2011-08-15T08:35:47+0000";
}
I don't see any way to get this information. Am I right or am I missing something?
It depends on the type of object you are accessing. Recently, Facebook have begun to hide useful info such as who specifically liked something, I'd imagine because they don't want people writing analytics packages for facebook but would prefer users to use the facebook system.
I know when it comes to images you can only get the number of likes , but not who they actually came from.
Your best bet is to use FQL which still lets you retrieve some of this information.