Replicating parse.com anypic in JavaScript - Unable to compare Fb users - javascript

I'm using parse.com to build the back end of my app. I want the user to be able to find their friends that are using my app and who they are friends with on Facebook.
I'm using JavaScript, however unlike IOS, here https://www.parse.com/tutorials/anypic#follow there are no examples on how to build the app
I have used the Fb SDK to pull back a users friend connections, but I'm stumped on how to proceed next.
I guess I need to run a query between the returned data and my current users data and look for matches and then return them?
Has any one experience doing this? can share some code or point me in the direction of external resources?
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
FB.api('/me/friends', function(response){
if (response && response.data){
for (var friendIndex=0; friendIndex<data.length; friendIndex++)
} else {
console.log('Something goes wrong', response);
}
});
}
});

The only way to do this reliably, which has nothing to do with language, is a multi-step process:
One: Provide a way to "connect to facebook". In this process, you pull the user's facebook id and store it as a field on the user profile in parse. This is the field you need to match friends.
You will only be able to reliably match the user's friends who has ALSO CONNECTED THEIR APP TO FACEBOOK (and thereby stored their facebook id in their user profile).
Two: Perform a query against Parse with the user's friends' facebook IDs. For every friend facebook id you find in your Parse user database, you display their name etc FROM FACEBOOK (so they recognize them easily).
This means that when you add this functionality, nobody will find their friends from facebook in their app. Only when some of their friends connect to facebook will they be able to find facebook friends like this.
You can i.e. check for this on app launch, and then notify the user that some of their facebook friends are now using your app.

Related

How to get facebook friends list using JavaScript

I have tried
FB.api('/me/taggable_friends?limit=500', function(response) {
alert(JSON.stringify(response));
}
Which gives me only administrators fb friends list
For other fb users - below error message
To use taggable_friends on behalf of people who are not admins, developers and testers of your app, your use of this endpoint must be reviewed and approved by Facebook. To submit this feature for review please read our documentation on reviewable features: https://developers.facebook.com/docs/apps/review
As I have already submitted my app for review and below is a screenshot that showing that I have an access of Friend List
If I use Facebook Developer Link for friend list then I don't know how to get and set "/{friend-list-id}"
/* make the API call */
FB.api(
"/{friend-list-id}",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
Please let me know if is there any working example for this or this is possible or not.
You have to get taggable_friends approved by Facebook, else it will only work for users with a role in the App. Don´t mistake this with user_friends and the /me/friends endpoint. that one you don´t need to get approved, but you only get friends who authorized your App with /me/friends.
In your App Settings, click on "App Review", then on "Start a Submission". Scroll down to "Taggable Friends".
Btw, you have to finish your App or at least create a working prototype, BEFORE you can send something in for review.

Automating posts from "company" for the Facebook page of said "company"

I put company in between quotations because my question relates to our Rugby team page but in Facebook it acts like a company page.
I am currently rebuilding my teams website (BBRFC Celtic) and I am going to add a user login system which will have coaches and admin staff with different levels of authority.
Sometimes due to weather conditions, events, or other things a training time may be changed or a match canceled or other various events. When these happen we normally send emails through a mailing list or sms or post on Facebook by hand.
What I want to have is a little bot of some kind that runs behind the scenes of the server and when coaches or admins change something it allows them to make an automated post to Facebook.
Something like after changing a trainings time it asking Would you like this to be posted to the facebook page and groups?.
I have been unsuccessful in finding out how I would go about writing the code for this. Our webpage will use php but maybe this can be done with javascript?
Do I need to get a key to post something as if I were the page?
How about to the different groups we have?
Any pointers would be helpful since I am totally stuck not really programmatically but more conceptually, I do not know if this is even possible.
I will explain the steps you need to accomplish your goal for a website. Note that the documentation also explains the case of a mobile application and others. I used the facebook API before, however, not to manage groups/pages, hence, this post will only point you in the right direction. I will explain how to post a message as being the admin of the page, not sure if you meant facebook pages or groups.
First, the user need to log in with facebook. This can be done using Javascript and the facebook API. Their documentation provides a very detailed explanation with code examples etc. Note that i will explain for the case of Javascript, however, this could be done in php, ...
Once the user is logged in, you can retrieve all kind of information about the user, his pages, etc. I would suggest to retrieve the pages the user is managing, then check if your "company" is part of this list (note that you will need the manage_pages permission). If this is the case, the user can post a message in name of the page.
/* Retrieve pages the user is managing */
FB.api(
"/me/accounts",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
Now response is an object containing multiple fields (see the official documentation).
Now, if the user is an administrator of your page, you can post a message as a Page.
/* Post a message as a Page, use your page id */
FB.api(
"/{page-id}/feed",
"POST",
{
"message": "The match has been delayed to ..."
},
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
If successful, the ID of the post will be returned as part of a JSON response (see doc)

How to import my own private facebook photos to my website?

I searched internet for hours and I couldn't figure out a simple way to do this ...
My goal is to let everyone who access my website see all my own facebook photos (so I will be using my own user id , not the logged in user) . I don't like to use Embedded Posts because I want photos to be synced with my own personal facebook photos every time a user refreshes the page...
So do I need to give my facebook app full permission to access my own profile so it can retrieve all my data without asking for login ?
one more thing , I'm really confused about where facebook permissions are stored in ? and how they work ?
You would need to use the Graph API to read the photos, this is the API call: https://developers.facebook.com/docs/graph-api/reference/v2.3/user/photos#Reading
You need a User Token for that, an Extended User Token is valid for 60 days and you need to refresh it manually every 2 months.
More information about Access Tokens and how to generate them:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/

Why is the Facebook user id picked up by Firebase different to the Facebook id associated with the same account in the Facebook Graph?

I have integrated Facebook authentication with Firebase into my website. I am using the Firebase JavaScript API.
The code I am using is lifted straight from the Firebase tutorial titled "User Login & Authentication" available here: https://www.firebase.com/docs/web/guide/user-auth.html
var myRef = new Firebase("https://#######.firebaseio.com");
var auth = new FirebaseSimpleLogin(myRef, function(error, user) {
if (error) {
// an error occurred while attempting login
console.log(error);
} else if (user) {
// user authenticated with Firebase
console.log("User ID: " + user.id + ", Provider: " + user.provider);
} else {
// user is logged out
}
});
auth.login("facebook");
This all works perfectly well, logging the correct information.
However, the id that is logged (i.e. the user id that visible in the data in the Firebase dashboard) is different to the Facebook id I get through Facebook Graph.
With Firebase, I get a 17-digit user id.
With Facebook Graph (https://developers.facebook.com/tools/explorer?method=GET&path=me%3Ffields%3Did%2Cname&version=v2.0), I get a 9-digit user id.
This means that I can't use Firebase to login, grab the Facebook id and make requests through Facebook Graph - the user ids for the same user are different.
Why does this difference exist? How can I use Firebase to get the same Facebook id that appears in Facebook Graph?
Facebook recently introduced version 2.0 of their Open Graph. With that came a lot of changes. One of them is the user ID returned by Facebook to Facebook applications. Instead of every app receiving a user's global Facebook ID, each app now receives what they call an "app-scoped ID." This means that every app will receive a different user ID for user X even though each unique ID still maps to user X. If you need to be able to map a user across multiple apps, you can use their Business Mapping API. Ultimately, this was a change Facebook made that we at Firebase have no control over.
If you are getting a 17-character ID from Simple Login, it probably is because your Facebook app was created before the change to Facebook login v2 happened (a little over a month ago). I see in your Open Graph Explorer request that it is using v2. But with Simple Login we are using a mixture of v1 and v2 depending on when your Facebook app was created. We are working on adding an option for you to decide what version of the Facebook Open Graph API you want to use, but have not added that yet. If you want to use v2 at this point, you just have to create a new Facebook app and everything should work. If you want to stay with v1, be aware that Facebook will stop supporting it in around 10 months.
Search for "App-scoped User IDs" on this page for their official changelog information.
The new user ID is returned in the providerData object within the object returned from Firebase on successful login.

JS SDK - Posting to a page wall

I am using the JavaScript SDK. I have an application that has publishing permissions and after certain actions are taken a post will be made to the logged in users wall like so:
FB.getLoginStatus(function (response) {
//we are authorized
if (response.status == "connected") {
var name = "Post name";
var body = "Post body";
var caption = "The caption";
var description = "The description";
var link = "http://www.facebook.com/mypage";
FB.api('/me/feed', 'post', { message:body,caption:caption,link:link,name:name,description:description}, function (response) {
console.log(response);
});
}
});
What I would like to able to do is post to a specific Facebook Page after a post is successfully made to the users page. Is there a way to securely pre-authorize an application to do that? Is this possible with the JavaScript SDK, or at all? I did some looking around and havn't found a definite answer. I'm looking at the FB documentation but find it to be a bit spotty in places. Could anyone tell me if this is possible? Any help or advice would be very much appreciated, thanks much!
Edit: my mistake, I should have supplied more info. Here is what I am trying to do:
var body = "The body";
var caption = "The caption";
FB.api("mypageid/feed", "post", { message: body, caption: caption }, function (response) {
console.log(response);
});
I am getting the error "this api call requires a valid app_id" however my page id is valid. When I call FB.init() I am passing my app id and it works for the first post to the logged in users feed.
Edit:
I have made the change the Igy suggested. Now I am getting the error:""(#200) The user has not granted the application the permission to automatically publish feed stories""
Now, as I said I am trying to post to a Facebook page. I have logged into the account that owns the page and I have gone to the app and clicked allow for the following permissions:
email,user_photos,publish_stream
When I am logged in with the account that owns the page and check my status:
FB.getLoginStatus(function (response) {
console.log(response);
});
I get "connected". Am I doing this incorrectly? Do I have to do more than just authorize with the account that owns the page? Is there a way to set allow permissions for a page? I did a little digging but couldn't find an answer.
Edit :
Ok, now what is happening is IF I am logged into the account that owns the page the post will be made to the page. If I am logged in with another account I get an id back as a response to the API call but it doesn't seem to be a valid object id. For instance I just got this back:
id: 499973616681852_507724422573438
if I go to http://graph.facebook.com/499973616681852_507724422573438
I get an "unsupported get request" graph api exception, which suggest that id returned is not valid. I feel like I am close here but I am missing something. Any advice would be appreciated, thanks again to all who responded.
edit: removed the link to the page,that was left in unintentionally.
It's good practice to try getting it to work in the graph explorer first. Note that on the top right you can select which application to run under. I just made a post to your page using /PAGE_ID/feed and it worked fine. You'll need the publish_stream permission. If you can get it to work in the graph explorer you'll know it's possible to get it to work in the JS SDK and you've just made some sort of syntax error.
Also note there is an open high priority bug report on some calls to the graph returning "unsupported get request". So even though the id you are getting back is invalid, check the page itself to see if the posts are appearing.
I also noticed that the user itself is getting the same error. Try https://graph.facebook.com/507724422573438. Is this a test user for your app? Might be worth trying this as a real user if so.
Since you want to post to the page as the page itself, you'll need to authenticate as a page and then use that access token when making graph api calls. I am not sure if you'll be able to then use this access token for any user, or only users that are allowed to manage the page. It would be best for you to use the graph explorer to do some experiments to find out.

Categories