So I have a Facebook page setup. And I have an external website that I would like to use facepile on. The idea being that when somebody comes to my external website, they can see which of their Facebook friends has 'liked' the Facebook page.
I went to here https://developers.facebook.com/docs/plugins/facepile/ and it says
The Facepile plugin displays the Facebook profile photos of people who
have connected with your Facebook page or app.
So it looks like I can do it with my Facebook page.
I found the following code
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '12345667809845', // App ID from the app dashboard
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
};
// Load the SDK asynchronously
(function(){
// If we've already installed the SDK, we're done
if (document.getElementById('facebook-jssdk')) {return;}
// Get the first script element, which we'll use to find the parent node
var firstScriptElement = document.getElementsByTagName('script')[0];
// Create a new script element and set its id
var facebookJS = document.createElement('script');
facebookJS.id = 'facebook-jssdk';
// Set the new script's source to the source of the Facebook JS SDK
facebookJS.src = '//connect.facebook.net/en_US/all.js';
// Insert the Facebook JS SDK into the DOM
firstScriptElement.parentNode.insertBefore(facebookJS, firstScriptElement);
}());
</script>
and then further down I have
<div class="fb-facepile" data-app-id='12345667809845' data-href="http://facebook.com/myfacebookpage" data-action="like" data-max-rows="1" data-colorscheme="light" data-size="medium" data-show-count="true"></div>
(Important urls and numbers changed to protect the innocent)
As you can see the code above is always talking about a Facebook app rather than a page. I would love it if somebody could tell me what I'm doing wrong!
UPDATE:
So to clarify:
What I want to do is to have Facepile display how many people liked my Facebook Page on an external website. It seems to me that something in the code that I insert into the external page needs to tell Facepile what Page it needs to get the likes from. And from the comments below it seems you do that in the data-href.
If so then what do I put in the app_id?
Do I need to register the external page as a facebook app to get the app id?
So the answer is yes. You can use FacePile with a FaceBook Page. But you need to do some other things first.
You need to register your external page as a FaceBook App. You can do this here
https://developers.facebook.com/apps
and Create a new app. You need to specify what you want to do with the app, I found it easiest to say I wanted to login with Facebook (Note that this functionality doesnt need to exist on your site, you just need to specify for FaceBook). You add your external site URL under the "Login to Facebook" option in the "Site URL" and voila you have a facebook app at your external website url. You also then have a app id.
So when you go to
https://developers.facebook.com/docs/plugins/facepile/
to get the code snippets you use the Facebook app your just created (there is a drop down box once you click the "get code" button or you can enter the number in the dialog) and the "URL" is the url of the Facebook Page that you want likes from. If you click the Get Code button you will get you some code snippets something like the following:
<div id="fb-root"></div>
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=<YOUR_APP_ID_HERE>";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script','facebook-jssdk'));
</script>
and
<div class="fb-facepile" data-href="http://facebook.com/<YOUR_PAGE_URL_HERE" data-max-rows="1" data-colorscheme="light" data-size="medium" data-show-count="true"></div>
Put those on your external page (after substituting the values) and facepile should work!
Hope this helps someone else!
Related
I am currently writing a website for a local charity run preschool and they would like their Facebook feed on the site.
For this I have used the Facebook Pages plugin. Unfortunately, following their instructions, I don't get anything on the website.
I'm not getting any errors in the console, and the Facebook URL is valid.
I understand to view this specific page the user needs to be logged in to Facebook, which I am, and I'm also able to view the page in the same browser with no problems.
The code I have is:
<div id="fb-root"></div>
<script>
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.8&appId=261857213845517";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
and the HTML is:
< div class="fb-page" data-href="https://www.facebook.com/thevillageplaygroup/" data-tabs="timeline" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true">< /div>
(note, I've added spaces in the div opening and closing tags as I couldn't get it to show up otherwise, sorry).
I've tried changing the Facebook URL to https://www.facebook.com/facebook as in the examples and that works so I'm presuming it's something to do with the page itself but I can't find any privacy or security settings which seem relevant.
EDIT
The page has security restrictions in place which mean the user needs to be logged in to Facebook and in the UK.
My account is able to access it ok through Facebook, just not using the plugin on the website
Any help is greatly appreciated.
As pointed out by CBroe, it looks to be an issue with using the page feed for a page with privacy restrictions
“Facebook Pages with privacy restrictions cannot be embedded.”
I, wrongly, assumed that seeing as was logged into Facebook and could access the page that I would be able to see the feed. It seems Facebook disallow use of the plugin for pages with privacy restrictions regardless.
I'm new in mobile development so I started with Xamarin.Forms
I'm part of organization which wants me to develope an Telephone Directory App (which is ready) and include their Facebook Page in it so that events can be shown in app itself
I tried to search web for some sort of help came out with different options but none can be implemented because
Facebook Page is created by another member with his personal ID
Various post suggest to access public posts using APP ID, App Secret & access-tokens generated from https://developers.facebook.com/
How can I generate an access-tokens for and facebook page which is created by another user and include it in my app.
What are the settings which I should do in Facebook Developer Console so that anyone using my mobile app can easily view facebook page in app and go to browser if he/she taps any image or post so that he can login to facebook and post his comment or like the page etc...
Please Guide me.
Amit Saraf
EDIT
CBroe
Yes, you would need a basic HTML document that contains the necessary code and embeds the FB JS SDK
Here is my HTML File
<HTML>
<BODY>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7&appId=<AppID>";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div id="fb-root"></div>
<div class="fb-page"
data-href="https://www.facebook.com/AkolaIndustriesAssociation"
data-tabs="timeline"
data-small-header="true"
data-adapt-container-width="true"
data-adapt-container-height="true"
data-hide-cover="false"
data-show-facepile="true">
<blockquote cite="https://www.facebook.com/AkolaIndustriesAssociation" class="fb-xfbml-parse-ignore">
Akola Industries Association</blockquote>
</div>
</BODY>
</HTML>
But it is Not working
Where I'm wrong
Edit
CBroe
Is this document called via http:// or https://? Otherwise the protocol-relative URL to the SDK can’t work of course, so you would need to add a protocol to the URL in the code. – CBroe 18 hours ago
XAML Code
<WebView x:Name="Browser" WidthRequest="1000" HeightRequest="1000"
Navigating="webOnNavigating"
Navigated="webOnEndNavigating" />
C# Code
Browser.Source = new UrlWebViewSource { Url = "file:///android_asset/AIA.html" };
I solved my problem with help of CBroe (See Comments to my Question).
Here are steps if anybody needs
Create a Developer Account on Facebook using https://developers.facebook.com/
Create a Facebook App and Make it Public by visiting -> App Review -> Make Public
Visit Facebook Plugin Page https://developers.facebook.com/docs/plugins/page-plugin/
Enter the details and click Get Code. Here you will received Java SDK Code and Facebook Plugin Code.
Using these codes prepared a simple HTML File (Sample Code Placed in 1st Edit of my Question).
These file needs to be accessed using http:// or https:// protocol (see comments) for which you need to place these page on web server and then access it (here I used free web hosting provided by https://www.000webhost.com/)
Add a Webview to your Xamarin.Forms content page and set its source to the url of your webpage on server. (in my case it is http://gsakola.comuf.com/AIA.html )
Done.
It works like a charm.
Thanks CBroe https://stackoverflow.com/users/1427878/cbroe for your great help.
Amit Saraf
I have a web app that uses Facebook Login. We would like to render Facebook "Follow" buttons for these users on their profile pages on our product.
However, the "Follow" button does not render when it's initialized with the profile URL we get from the graph API for the user when they auth to our app.
I can only get it to work when the URL used in the button is their primary Facebook account URL, which I can locate manually, but not programmatically. We don't seem to have access to this URL via the graph API or the Javascript SDK.
Example markup that I expected to work, using the profile URL given in the "link" edge on the user graph node (note this employs the app-scoped user ID):
<div class="fb-follow" data-href="https://www.facebook.com/app_scoped_user_id/812839870448/" data-layout="button" data-show-faces="false"></div>
Example markup that actually works using a non-app-scoped user name:
<div class="fb-follow" data-href="https://www.facebook.com/yetanotherjosh" data-layout="button" data-show-faces="false"></div>
Rendering a follow button for a user who has authenticated to your app seems like a simple enough task, what have I missed? Thanks!
p.s. - in case you are wondering if the JS SDK isn't loaded correctly, we're loading it via this code, as suggested by the Facebook developer site, inside the body tag (and the button does work with certain URLs, so I don't think the SDK setup is the issue):
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5&appId=REDACTED";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
I want to do the same thing and I have the same problem with the php api.
In theory you could do the following thing:
Have a php script follow the https://www.facebook.com/1234 url to it's end point: https://www.facebook.com/username
Step 1 is very slow, so you should do it only once, maybe use a cron job, not on-the-fly when the user logs in. Then store that url in your DB.
Use the stored url to generate the Follow button.
For step 1. you can use How to get final URL after following HTTP redirections in pure PHP?
but make sure you add a user agent:
$request .= 'User-Agent: Safari/537.16\r\n';
or otherwise you'll get redirected to /unknownbrowser
I will try it myself and post the results if any.
Later Edit: i tried it and facebook needs you to be logged in to get the final url so you could, again in theory, start a login flow to get to the url, but it would probably be overkill.
Hi i'm trying to place a facebook like button in website With the following code
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
FB.Event.subscribe('edge.create',
function(response) {
alert("Thank you for liking my page");
}
);
</script>
<div class="fb-like-box" data-href="https://www.facebook.com/mypage" data-width="292" data-show-faces="true" data-stream="true" data-show-border="true" data-header="true"></div>
But the FB.Event function not working when i tested, I think i can use this trigger event only if i use FB.init and running inside fbAsyncInit() function.this came to know by searhing web.
i don't know these things exactly.Now the problem is Fb.init require appId,channelUrl and few more.I'm confused i didn't created any Application and i'm not creating i'm just trying to place a facebook like button to my website then how come can i provide appId.
Can anyone explain me about this appId.Does it required to create like button and to create Fb.event when a user likes my page like thanking them or am i using the given code wrongly?
It is recommended to use an App Id for every Social Plugin (like the Like Button).
And here´s an overview of how you should implement the Facebook SDK:
https://developers.facebook.com/docs/javascript/quickstart
You better place that FB.Event code right where it says "Additional initialization code..." - Because right now, you are using "FB" when it´s not even initialized.
And this is where you can create an App: https://developers.facebook.com/apps
Here's some docs about the app id —
search for fb:app_id on this page: https://developers.facebook.com/docs/sharing/webmasters#markup
You specify the app id, so that you can use Facebook Domain Insights to view analytics for traffic to your website from Facebook. Apparently FB Domain Insights is some FB tool that webmasters can use to get information about how the content on their website get shared inside Facebook.
However the FB page about Facebook Domain Insights is gone ... and instead says you should look for some "platforminsights" tool. I suppose FB made some changes to their analytics stuff, recently.
Is there a simple URL string that Facebook will accept to "like" a site... or more accurately (as a commenter points out below), share a site? As a comparison, Twitter allows you to post from any page simply by pointing an anchor at a customized URL... like this:
Tweet this!
I can't seem to find anything in the Facebook documentation.
Not exactly an answer, but close enough for me:
http://www.facebook.com/sharer.php?u=http://mysite.com/
That'll do it.
There is a non-depreciated equivalent to the twitter or sharer.php functionality, though it is way more annoying. This doesn't exactly answer the question about "liking" a page but does accomplish the exact analogy to the twitter share, which seems to be what the question is asking.
https://developers.facebook.com/apps/ - make a new app with a developer account.
Make the Display Name the name of your business or website
add your domain without http under App Domains
add your base URL under Website with Facebook Login (with http )
Grab the App ID
Now make your url like this:
http://www.facebook.com/dialog/feed?app_id=000000000000000&link=http://example.com/whatever&redirect_uri=http://example.com/backtothesite
You would think the redirect_uri would default to the user's facebook home or to the link parameter, but it's a required field.
More parameters here: http://developers.facebook.com/docs/reference/dialogs/feed/
No, Facebook only permits Liking a page via a Like button.
At the bottom of this page:
http://developers.facebook.com/docs/share/
Feel free to create your own implementation based on this.
There is a way how to do it, but not very comfortable for users, because they must click on 'like' button twice.
https://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2F
http%3A%2F%2Fexample.com%2F is url encoded version of http://example.com/ .
Or you can place this link into iframe and then only one click is needed for liking of url
It's a little more verbose with Facebook to do the same thing.
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId={YOUR_APP_ID}";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like"
data-href="http://mysite.com"
data-send="true"
data-width="450"
data-show-faces="true">
</div>