Facebook Graph API, Action ID and which object - facebook

I have a FB App and I can successfully post actions and objects with the Open Graph API to the timeline, ticker, and chronicle.
My question is, is there a way to get the action id returned written into the mysql database or from the action id get the actual object title returned and written this to the database?
Thanks for your help.

You could do this with AJAX.
For example:
function postNewAction()
{
passString = '&object=http://site.com/APP_NAMESPACE/object.php';
FB.api('/me/APP_NAMESPACE:ACTION' + passString,'post',
function(response) {
if (!response || response.error) {
alert(response.error.message);
}
else {
storeInTable(response.id);
}
}
);
}
function storeInTable(id){
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//Success!
}
}
xmlhttp.open("GET","storeInTable.php?id=" + id,true);
xmlhttp.send();
}
And then you would store the id to your table in storeInTable.php of course.
This may not be the best way - maybe it is, I don't know - but will do what youre requesting.

Related

FB.api post to multiple ids at same time

I'm having a little trouble here. I'm not good at javascript and all.
The problem is that I'm trying to post to some Facebook users using FB.api. However, it only works if it's only one friend at a time.
Here's my code:
FB.api({ method: 'friends.get' }, function(result) {
var user_ids="" ;
var totalFriends = result.length;
var randNo = Math.floor(Math.random() * totalFriends);
var numFriends = result ? Math.min(1,totalFriends) : 1;
if (numFriends > 0) {
for (var i=0; i<numFriends; i++) {
user_ids+= (',' + result[randNo]);
randNo ++;
if(randNo >= totalFriends){
randNo = 0;
}
}
}
FB.api(user_ids + '/feed', 'post', { message: txt2send },function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
});
The output of user_ids is looking like this: ,10083461349,100082391,19293822
Hope you can help me solve this. And please don't refer me any links to help, trust me, I've tried everything.
Hope you can help me solve this. And please don't refer me any links to help, trust me, I've tried everything.
Yeah, sure. But instead of sticking to what the docs say, you’re trying to invent your own “syntax” – you really think that’s helpful …?
Accessing the Graph API generally works by making HTTP requests to /someid/someendpoint/.
But what you are trying, is to (eventually) make a request to
/,10083461349,100082391,19293822/feed
– which is just complete and utter nonsense. You just can’t access the Graph API listing multiple ids at once.
If you want to post to several user’s feeds, you have to make one API call for each one of these users.

How to get facebook user id without calling FB.getLoginStatus and promting user to grand access for public information

I am developing asp.net web site to be facebook application.
I am trying to make "Facebook Like Gate" to promt user Like my page before he can see the application. For example https://www.facebook.com/AvonProductsInc?sk=app_188308831197082.
The problem is that application above does not aks me for permission to get my basic information, but i have to promt user give me such permission before i can use following code to get user_id and check wether he has already Liked my page:
function checkFBlike() {
//FB.login
FB.getLoginStatus(function (response) {
var r = response;
if (response.status == "connected") {
var user_id = response.authResponse.userID;
var page_id = "341342102543433"; //341342102543433 168619489865949
var fql_query = "SELECT uid FROM page_fan WHERE page_id = " + page_id + "and uid=" + user_id;
var the_query = FB.Data.query(fql_query);
the_query.wait(function (rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
//jQuery("#container_like").show();
fbLikeGateHide();
//here you could also do some ajax and get the content for a "liker" instead of simply showing a hidden div in the page.
}
else {
//and here you could get the content for a non liker in ajax...
}
});
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook, but not connected to the app
showFbLogin(); //display Facebook Login button
}
else {
// user is not logged in
}
});
}
function showFbLogin(){
FB.login(function(response) {
var r=response;
});
}
Since you're going to be like the avon app (specifically a page tab application) You should look at the signed_request parameter coming from the HTTP POST that Facebook does when your page is a canvas app. You really don't need to do any client side checks.
For more information about the signed_request, see: http://developers.facebook.com/docs/authentication/signed_request/

How should I retrieve original pictures included with the Facebook posts?

My application uses the Facebook Javascript SDK to add wall posts to the feed of a community's page, and to retrieve them again. Pictures included with the posts are processed and placed somewhere on the Facebook servers.
When these posts are retrieved the links to the pictures turn out to be links pointing to the fbcdn.net server.
Is there a way to access the original links?
Update:
Here is my code posting a post:
// The "params" variable contains a field called "picture"
// (which is a link pointing to my picture)
FB.addWallPost = function (params, pageId, token, complete) {
var fbApiParams = {
access_token: token
};
$.extend(fbApiParams, params);
FB.api(pageId + '/feed', 'post', fbApiParams, function (response) {
// FB.apiCallDone is a function checking if there's any positive response
if (FB.apiCallDone(response)) {
complete(response.id);
}
else {
complete(null);
}
});
}
And these lines retrieve the posts:
FB.getWallPosts = function (wallPostsIds, token, complete) {
if (wallPostsIds && wallPostsIds != null && wallPostsIds.length) {
var wallPostsIdsStr = wallPostsIds.join(',');
var fbApiParams = {
ids: wallPostsIdsStr,
access_token: token
};
FB.api('/', fbApiParams, function (response) {
if (FB.apiCallDone(response)) {
var wallPosts = dictElemsToArr(response);
complete(wallPosts);
}
else {
complete([]);
}
});
}
else {
complete([]);
}
}
If you're posting pictures to Facebook, they will be stored locally by Facebook.
It is up to your application to store the path of the original images if your application requires this information.

Check if current user (session) is fan of my page or not

I need using javascript to check if the current user is fan of my page.
I goto here https://developers.facebook.com/docs/reference/rest/pages.isFan/. In Test Console I don't understand about Application parameter?
I using this code below, but it's always alert "You like the Application" for any user even guest
window.checkDoesLike = function() {
FB.api({ method: 'pages.isFan', page_id: '138992766181857' }, function(resp) {
if (resp) {
alert('You like the Application.');
} else {
alert("You don't like the Application.");
}
});
};
I've written an extended tutorial about this here.
There are a couple of points to highlight:
You are missing the uid parameter
using if(resp) is not enough
Better code:
FB.api({ method: 'pages.isFan', page_id: 'page_id_here', uid: 'user_id_here' }, function(resp) {
if (resp == true) {
alert('user_id likes the Application.');
} else if(resp.error_code) {
alert(resp.error_msg);
} else {
alert("user_id doesn't like the Application.");
}
});
Quoting:
Once again, you need to check the response of the call if true or
not…using if(resp) is NOT enough! The example in the Facebook
JavaScript Test Console is a bit misleading (the does-like example),
since if you don’t grant the user_likes permission and just try it
with uid: '579187141' it would result that the user likes the
application which is not true!
P.S: I just decremented my user id to get the above user which (it
seems) he has a strict privacy for pages he likes!

Receiving response from facebook login

I am writing a flash app in AS3. I am using the com.facebook.graph library to get the login from my app to work.
If the user is not signed into facebook, a popup appears asking them to enter their username and password like it should. however the issue is that it doesnt seem to be returning to the callback function.
The JS code used to connect looks like this:
function redirect() {
var params = window.location.toString().slice(window.location.toString().indexOf('?'));
top.location = 'https://graph.facebook.com/oauth/authorize?client_id=myappID&scope=publish_stream&redirect_uri=http://mydomain.com.au/play.php?'+params;
}
and the AS code looks like this:
Facebook.init('myappID', handleLogin);
function onLoginButtonClicked(event:MouseEvent):void
{
if (Facebook.getSession()==null ||
Facebook.getSession().uid == null)
{
Facebook.login(handleLogin);
}
else{
handleLogin();
}
}
function handleLogin(response:Object, fail:Object):void
{
if (response == null)
{
ExternalInterface.call('redirect');
return;
}
postToFB();
}
function handleUploadComplete(response:Object, fail:Object):void {
//call back from posting
}
function postToFB() {
messageText.text = 'done';
}
If the user is already logged in , then it runs the posttoFB function correctly, however, if they are not and it goes through the login procedure, it does not run the function. It seems to just not run the callback function upon completion of the signin process.
What am I missing here?
yhou might want to take a look at this page:
http://www.adobe.com/devnet/facebook/articles/flex_fbgraph_pt4.html