Facebook page post as admin using javascript api - facebook

I do lots of stuff in my javascript code for posting feed in page as m`, but how i can get permission through javascript with just one click.
This is my code.
<body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p>
<a href="javascript:;" onclick='postToFeed(); return false;'>Post to Group</a>
</p>
<p id='msg'></p>
<script>
FB.init({appId: "apid", status: true, cookie: true});
function postToFeed() {
FB.api('/page_id/feed', 'post',
{
message : "It's awesome ...",
link : 'http://csslight.com',
picture : 'http://csslight.com/application/upload/WebsitePhoto/567-grafmiville.png',
name : 'Featured of the Day',
from: 'pageid',
description : 'CSS Light is a showcase for web design encouragement, submitted by web designers of all over the world. We simply accept the websites with high quality and professional touch.'
},
function(response) {
alert(JSON.stringify(response));
});
}
</script>
</body>
Output of above script is
But i wan't to post as a BeCrazzy.com not Rajnish..!
simply, i want to post feed in page as a admin. please help me. :)

There is a tutorial here that shows you exactly how to do this:
https://developers.facebook.com/docs/howtos/login/login-as-page/
You will not be able to use the Facebook Javascript SDK to make the API call signed with the Page access token, you'll need to use something like jQuery.ajax() to do so.

Related

LinkedIn API calling in Javascript

I have used the LinkedIn Javascript API calls in my html page. I can see the "Sign In With LinkedIn" button . In "onLinkedInLoad" function calling the "IN.Event.on("IN", "auth", onLinkedInAuth);" is not firing. I have an alert message 'call2' in my code and its also not calling.
Basically I want to read a company updates and bind into a div. In Browser console I am getting the below URL and profile's response. There is no other request in browser console.
https://api.linkedin.com/v1/people::(~):(id,first-name,last-name,headline,picture-url)
I followed all the instructions in LinkedIn document before doing this to consume a company update.
I have a company page and with an update.
I have created an app and use that api key only in js function call.
In LinkedIn REST Console I can see my update.
Do I miss anything ? Thanks.
I use the actual api key and company id at my end.
See my code :
<html>
<head>
<title>
LinkedIn
</title>
<script type="text/javascript" src="https://platform.linkedin.com/in.js">
api_key: 0000000000000
onLoad: onLinkedInLoad
authorize: true
</script>
<script type="text/javascript">
function onLinkedInLoad() {
alert('call');
IN.Event.on("IN", "auth", onLinkedInAuth);
}
function onLinkedInAuth() {
alert('call2');
IN.API.Raw("/companies/000000/updates")
.method("GET")
.result(function(res) {
document.write(JSON.stringify(res));});
}
</script>
</head>
<body>
<script type="IN/Login">
</script>
</body>
</html>
I have used IN.User.authorize(onLinkedInAuth) instead of IN.Event.on("IN", "auth", onLinkedInAuth) for authorization and worked.

How to create a different URL for Facebook Custom Action

I am trying to add a custom link to the [object] (marked in red, below) in a facebook custom Action post.
This is my code :
FB.api('/me/testapponens:cook', 'post',
{ recipe: 'http://foobar.com/page1.html' },
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
Now, Because I have stated 'http://foobar.com/page1.html' in my 'recipe', when this is posted, the open-graph properties are picked from this page.
PROBLEM : I need to show the link as a thirdparty link www.thirdparty.com/page1.html but the open graph meta properties cannot be written in thirdparty.com/page1.html (as I don't have any control on that page).
So, I decided to do this:
i) Create a dummy page : www.foobar.com/page1.html.
ii) Add all the og meta to it.
iii) Add a redirect (javascript) code to the dummy page so that it goes to the third party page.
www.foobar.com/page1.html looks something like this :
<html ...>
<title> Page 1 </title>
<meta property="fb:app_id" content="..." />
...
<script type="text/javascript">
function redirect1()
{
window.location = "http://thirdparty.com/page1.html"
}
</script>
</head>
<body onLoad="redirect1()"></body>
</html>
QUESTION : I think this is a hacky approach and it may not be acceptable to the users. Is there a better way of doing this? Please let me know if I was not able to explain what I intend to do.
PS : I am not a spammer, the third party page is from a client and I am not trying to misguide the users.
I think this is a hacky approach and it may not be acceptable to the users. Is there a better way of doing this?
You can do a server-side redirect, checking the user agent – only if it is not indicating to be the Facebook scraper, redirect the client, otherwise let the scraper read the OG meta info from your page.
How to detect the FB scraper: https://developers.facebook.com/docs/reference/plugins/like/#scraperinfo

Facebook Like notifications?

I saw a website today that stated: "Share/Like this site and get 10% discount". I was wondering: is there any way to track when someone shares/likes my site? Can I store some data of that user in my app?
I know those events have some callbacks, and maybe I can trigger some jQuery magic to send some data vía ajax when the user clicks on the button.
Any ideas?
Thanks!
Similar question was discussed here
FB.Event.subscribe('edge.create', function(href)
{
});
From the above code you can get only href not any User details. So I tired the following code
FB.Event.subscribe('edge.create', function (href) {
FB.login(function (response) {
if (response.session) {
//session object has uid & access token.
}
});
});
The Problem you will have from above code is: Since FB.login will open a pop up window for log in, some browsers will block the pop up or warns the user.
I tried the above code. LIKE functionality works and is posted to user's wall, but regarding getting user info:
Firefox (4.0) - did not warn but it asked the user to authorize APP and access basic information. IE 9 - Gave a warning message about POP UP. Google Chrome : Blocked the log in pop up.
It seems the only way to achieve this is let the user login to website using Facebook Connect first and then get user info using
FB.Event.subscribe('edge.create', function (href) {
// href is the URL of the object that got liked
var x;
FB.getLoginStatus(function (response) {
alert(response);
if (response.session) {
}
});
Check out the Facebook developers site. It contains heaps of information.
http://developers.facebook.com/search?q=Events.create
and
http://developers.facebook.com/blog/post/149/
Something like this should do what you need:
<fb:like href="http://www.google.com"></fb:like>
<!-- Like button to whatever object you want^^ -->
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"
type="text/javascript" charset="utf-8"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"
type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
FB.init({
appId: 'APP_ID',
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('edge.create', function(href)
{
// href is the URL of the object that got liked
// do whatever magic ajax you want
});
</script>

Facebook connect ifUserConnected() does not work - FB.Connect is undefined error

I'm trying to integrate Facebook connect to my website. The login button appears and i'm able to login. The profile picture and the name is displayed properly. However when I try adding the code FB.Connect.ifUserConnected, I get a error message saying FB.Connect is not defined.
This is what I'm doing
<div id="fb-root">
</div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
FB.init({ appId: 'my app id', status: true, cookie: true, xfbml: true });
</script>
<fb:login-button onlogin="fb_login()"></fb:login-button>
<script>
function fb_login() {
$("#SocialConnectButtons").hide();
$("#UserProfile").show();
FB.XFBML.Host.parseDomTree();
}
//ALL UNTIL HERE WORKS AS EXPECTED, BUT THE FOLLOWING LINE FAILS
FB.Connect.ifUserConnected(fb_login);
</script>
Thanks for the help
Here is a good tutorial to get started with new API for facebook connect.
You are using the new Graph API (http://connect.facebook.net/en_US/all.js)
The code you wrote will not work. Check the Graph API javascript SDK here: http://developers.facebook.com/docs/reference/javascript/
and for the API itself:
http://developers.facebook.com/docs/reference/api/

Connect to Facebook with Javascript Client Library using Adobe AIR

I'm having an issue connecting to Facebook through the Javascript Client Library in Adobe AIR. It works fine in the browser but in Adobe AIR it seems to not be able to find the Facebook functions. Here is some code I copied from the Facebook website: (Oh and I have the xd_receiver.htm file in the correct path too)
<textarea style="width: 1000px; height: 300px;" id="_traceTextBox">
</textarea>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
//
var api = FB.Facebook.apiClient;
// require user to login
api.requireLogin(function(exception){
FB.FBDebug.logLevel=1;
FB.FBDebug.dump("Current user id is " + api.get_session().uid);
// Get friends list
//5-14-09: this code below is broken, correct code follows
//api.friends_get(null, function(result){
// Debug.dump(result, 'friendsResult from non-batch execution ');
// });
api.friends_get(new Array(), function(result, exception){
FB.FBDebug.dump(result, 'friendsResult from non-batch execution ');
});
});
});
//]]>
</script>
It's not that simple actually man, the problem with loading external script files from the application sandbox is that it's not supported. Technically, by using iframes, you should be able to do this and it works but it's still impossible to use XFBML in the root document after from my experience. After two days of trial and error, the easiest way to do use Facebook Connect in an html/ajax adobe air application is to download the actionscript library and include it as such:
<script type="application/x-shockwave-flash" src="lib/facebook.swf"></script>
<script type="text/javascript">
var FB = window.runtime.com.facebook;
var fb = new FB.Facebook();
var session = new FB.utils.DesktopSessionHelper();
//etc...
</script>
then just refer to the documentation. my only problem now it that I still haven't found an efficient enough way of using XFBML in adobe air, simply adding the facebook namespace to the html tag doesn't do the trick unfortunately. If any knows, please do share thanks
you also need to change xml namespace (main html tag) to this:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="en-gb" lang="en-gb">