Customizing plays fbconnect module - facebook

When i'm trying to log in to facebook with button from fbconnect module, I am getting nullpointer at this line:
String email = data.get("email").getAsString();
where data is JsonObject. So I checked this json response from facebook, and found that has many data, but email isn't included.
I suppose i have to change something in fbconnect module, like change request, to get more data from facebook, can somebody tell me where and how ?
Im talking about play framework ofc.

You need the email extended permission to access the email field for a user - ensure you have this by calling /me/permissions with your access token - it'll show you the permissions your access token has

Add the email scope tag to your fbconnect button:
#{fbconnect.button label:'Login using your facebook account.', scope:'email'/}

Related

too short FB accessToken in Kinvey _socialIdentity using kinvey-nativescript-sdk

I have working log-in process with Facebook using Kinvey MIC in my NativeScript app. I am able to log-in into the Kinvey and _socialIdentity record is successfully created. Due to the fact that I need to know also user's email registered with FB account (that is not sent in basic User response from FB), I need to query FB Graph API for that.
https://graph.facebook.com/v3.2/me?fields=id,name,email&access_token= + accessToken
If I use a accessToken stored in Kinvey's _socialIdentity, FB returns:
"error": {
JS: "message": "Invalid OAuth access token.",
JS: "type": "OAuthException",
JS: "code": 190,
JS: }
If I use accessToken generated by FB developers tool and hardcode it into my NS code, everything works well - I receive all requested info.
The difference I found is length of the accessToken:
accessToken stored in Kinvey has 40 characters but the one generated by FB tools has 247 characters.
Could somebody explain why FB accessToken in Kinvey's _socialIdentity is short/impossible for further use or how to get a valid accessToken using kinvey-nativescript-sdk?
Also if somebody achieved to get an user's contact email from FB account using kinvey-nativescript-sdk.
Thank you
Can you try adding client_token to the Allowed Attributes section of the Mobile Identity Connect service configuration?
That will create a new attribute on the kinveyAuth object (that is contained in the _socialIdentity attribute of the User entity), which will hold the access token that you are talking about.
Can you try that, and let me know if it works?
Edit: You can also try adding idp_access_token to the Allowed Attributes section. That will directly create an attribute to the kinveyAuth entity, which will hold only the needed token.

How to simply use facebook login for my app without using the SDKs?

Is there a simple flow (hello world) for a user to login using facebook?
Found documentation on Manually Build a Login Flow, but is too full of text and details that I don't see the main flow.
Based on Manually Build a Login Flow (showing only the minimal data needed to make it work):
Create a facebook app.
Simulate the user clicking on the following authentication URL to allow the app to access the user's data: https://www.facebook.com/v2.8/dialog/oauth?client_id=<app id>&redirect_uri=http://localhost/
Click ok/accept/whatever to authorize access.
You get redirected by facebook to a URL of the following: http://localhost/?code=<code>
Take the code and invoke the following: curl 'https://graph.facebook.com/v2.8/oauth/access_token?client_id=<app id>&redirect_uri=http://localhost&client_secret=<app secret>&code=<code>'
You get a result like the following: {"access_token":"<access token>","token_type":"bearer","expires_in":5183924}
You can then use the access token to call API related to the user that gave the permissions to your app. Example: curl 'https://graph.facebook.com/v2.8/me?access_token=<access token>'
Example response: {"name":"Alik Elzin","id":"<app related user id>"}
* Remember to add http://localhost/ to the app's Valid OAuth redirect URIs - under app settings.
Have you checked out this documentation from Facebook? It's pretty short to read through: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow

Generate access token Instagram API, without having to log in?

So I am building a restaurant app and one of the features I want is to allow a user of the app to see photos from a particular restaurant's Instagram account.
And I want a user to be able to see this without having to login to their Instagram account, so they shouldn't even need an Instagram account for this to work.
So I have read this answer How can I get a user's media from Instagram without authenticating as a user?
And I tried what it said and used the client_id(which I recieved when I registered my app using my personal Instagram account), but I still get an error back saying :
{
meta: {
error_type: "OAuthAccessTokenException",
code: 400,
error_message: "The access_token provided is invalid."
}
}
The endpoint I am trying to hit is :
https://api.instagram.com/v1/users/search?q=[USERNAME]&client_id=[CLIENT ID]
So do I absolutely need an access token for this to work(and thus have to enforce a user to log in) ?
If I do, then is there way to generate an access token somehow without forcing the user log in?
I believe there is a way around this, as the popular dating app Tinder has this desired functionality I am looking for, as it allows you to see photos from people's Instagram account without having to log in! (I have just verified this 5 minutes ago!)
Any help on this would be much appreciated.
Thanks.
Edit April 2018: After facebook privacy case this endpoint is immediately put out of service. It seems we need to parse the JSON embedded in <script> tag directly within the profile page:
<script type="text/javascript">window._sharedData = {"activity_counts":...
Any better ideas are welcome.
You can use the most recent link
GET https://www.instagram.com/{username}/?__a=1
to get latest 20 posts in JSON format. Hope you put this to good use.
edit: other ways aren't valid anymore:
https://www.instagram.com/{username}/media/
Instagram used to allow most API requests with just client_id and without access_token, the apps registered back in the day still work with way, thats how some apps are able to show instagram photos without user login.
Instagram has changes the API specification, so new apps will have to get access_token, older apps will have to change before June 2016.
One way you can work around this is by using access_token generated by your account to access photos. Login locally and get access_token, use this for all API calls, it should not change, unless u change password,if it expires, regenerate and update in your server.
Since the endpoints don't exist anymore I switched to a PHP library -
https://github.com/pgrimaud/instagram-user-feed
Installed this lib with composer:
composer require pgrimaud/instagram-user-feed "^4.0"
To get a feed object -
$cache = new Instagram\Storage\CacheManager();
$api = new Instagram\Api($cache);
$api->setUserName('myvetbox');
$feed = $api->getFeed();
Example of how to use that object -
foreach ($feed->medias as $key => $value) {
echo '<li><img src="'.$value->thumbnailSrc.'"></li>';
}

MVC5 Facebook get users photos

I am building a website app in MVC5 that allows a user to login using Facebook/Twitter. Once they are logged in we will look through their photos for ones marked with a certain hashtag.
I have the login working for both FB and Twitter - and using Linq2Twitter I can get the and post photos.
However with Facebook I am having some problems. My understanding with Facebook is that after the login I have to make a second call to https://graph.facebook.com/oauth/access_token in order to get a short lived access token.
However this call requires a "code" and a returnUri. I am unsure what this code is or how to get it, and what return URI to use.
My startup.Auth.cs looks like this
var facebookOptions = new FacebookAuthenticationOptions();
facebookOptions.Scope.Add("user_photos");
facebookOptions.AppId = ConfigurationManager.AppSettings["facebookAppId"];
facebookOptions.AppSecret = ConfigurationManager.AppSettings["facebookAppSecret"];
app.UseFacebookAuthentication(facebookOptions);
And everything logs in fine and I end back at ExternalLoginCallback
So where do I go from here. How do I find this code and what returnUri do I use in order to get the access code.
Once I have this access code I plan to call (https://developers.facebook.com/docs/graph-api/reference/v2.1/user/photos)
Hopefully I am going about this the correct way and my question makes sense
Many thanks.
Okay - This solves my problem
http://blogs.msdn.com/b/webdev/archive/2013/10/16/get-more-information-from-social-providers-used-in-the-vs-2013-project-templates.aspx

Facebook Logout in iPhone Application

I have integrated the facebook in to my application, From the FB i will be getting the userid and the name of the user and passing it to my own service that will do the validation and allows the respective user to get in to the system. I have got the userid and username from the FB and passed it my service that will do the validation,it allows the user to enter in to app, but my problem is once i logged in , how can i log out from the FB ?
Please let me know your ideas.
Thanks
If you are using the new facebook sdk, then us
[facebook logout:delegate]
Being facebook your Facebook object,and delegate an FBSessionDelegate.
If all goes well your delegate will be called on -(void)fbDidLogout;
That depends on which library you use to connect to facebook.
But I guess that you have a FBSession class that has a logout method...
That logout method also calls deleteFacebookCookies that you could also directly call depending on your needs...
Hope that helps.
If you are using old facebook sdk,then use this code for logout.make FBSession class object and code like this. [FBSessionclassobject logout];
it will delete all FacebookCookies.