React-Native-fbsdk read and publish - facebook

I use react-native-fbsdk to login my users into my application like that :
LoginManager.logInWithReadPermissions(["public_profile", "email", "user_birthday", "user_location", "user_about_me"])
But i need to permit to my users to share some informations to their facebook feed ! So i need to have 'publish_actions' permissions and it's not working with 'logInWithReadPermissions' and, i can't set read permissions with 'logInWithPublishPermissions' !
So how can i do that ?
Thanks!

There is a logInWithPublishPermissions function too: https://github.com/facebook/react-native-fbsdk/blob/master/js/FBLoginManager.js
...although, you should consider using the Share Dialog, it does not need publish_actions: https://github.com/facebook/react-native-fbsdk
Make sure you don´t ask for read and write permissions at the same time, you only need write permissions just before the user wants to share something anyway, not when he logs in.

Related

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>';
}

Enforce Permission for Facebook's JS-SDK

My login code looks like so:
FB.login(statusChangedHandler, {
scope: 'email,'
});
I would like to enforce the email permission in such way that a user who
disabled it would not have the ability to login to the app - he will get an
error message and be prompted to login again.
Is there any built-in (Facebook's) method of doing such a process?
You can´t enforce it, you can only check after the authorization. An easy way is to use return_scopes, as you can read in the docs: https://developers.facebook.com/docs/reference/javascript/FB.login/v2.3#permissions

Facebook on/off social reading in app

I try social plugin "Recommendations Bar" and it works. It has a built-in function to activate and deactivate the social reading function.
I want to enable this function in my simple app with "read" publish_actions.
I don't want to use cookies or session var to do this, it's a wrong way.
Users have to choose in which article on/off the social reading and change his preference on the fly.
User login with:
scope="publish_actions, email"
I know:
$facebook->api("/me/permissions");
$facebook->api("/me/news.reads?limit=10");
and I can post reads:
FB.api('/me/news.reads',
'post',
{ 'article': 'xxxxxx',
'access_token': 'xxxxx' },
function(response)
and delete it:
FB.api(id, 'delete', function(response)
Any idea for API call to enable/disable social reading function?
How to set publish_actions permission value to 0/1 for the users having app installed?
I dont want to use cookies or session var to do this, it's a wrong way.
Right, the user’s profile would be a better place to save this, so that he doesn’t have to make that decision again next time he visit’s your site.
How to set publish_actions permission value to 0/1 for the users having app installed?
You can’t revoke permissions via app. And I can’t see why you would want to. If a user disabled social reading on your site (which you save in their profile, preferably), then just don’t post anything on their behalf.

Is there any easy way to "provide" more permissions for my facebook connect app, using sfFacebookConnect

From what I see now, it seems that the plugin provides me only authenticated facebook user's email address.I need the first name, last name, and other data.
With my plugin (few month ago) the facebook_connect setting in app.yml did not work.
So, I've put this for the fb login button :
<img src="/images/fb_dark_medium_short.gif" alt="Facebook Connect" style="width:100px"/>
You can add in the scope GET parameter your permissions.
Hope this can help
by setting:
facebook_connect:
user_permissions: []
you can request some of those permission: http://developers.facebook.com/docs/authentication/permissions/

Facebook Graph API - get friends info

I'm trying to figure out how to get users friends information using either Graph API or FQL
Just for testing I would like to get my friends education_histroy.
To do that I created a test app, requested extended permissions using
scope=offline_access,manage_friendlists,friends_work_history,
friends_education_history,friends_about_me
and got access token to play with the API.
It works great when I query for current user using /me. But it returns nothing for my friends.
I was assuming that if I request, let's say friends_work_history, that extra field (work_history) will appear inside friend's object, when I query by friend's id:
https://graph.facebook.com/FRIEND_ID&access_token=TOKEN
But all I see is basic info about that user (friend).
Then I tried to request that field specifically:
https://graph.facebook.com/FRIEND_ID?fields=work&access_token=TOKEN
With no luck again. Returns just friend's id..
I tried to access that information with FQL:
https://api.facebook.com/method/fql.query?query=select+work_history+from+user+where+uid+in+(FRIEND_ID)&access_token=TOKEN
Returns work_history = TRUE instead of array. And that friend definitely has work history specified.
Can someone help me to understand how to get friends info using my app and extended permissions?
Graph API is the smart choice in most cases. To retrieve your friend information you need to collect some extended permissions from the user first. Then you can retrieve a lot more information other than the basic ones.
Following is a list of extended permissions related to friends different kind of information
friends_about_me
friends_activities
friends_birthday
friends_checkins
friends_education_history
friends_events
friends_games_activity
friends_groups
friends_hometown
friends_interests
friends_likes
friends_location
friends_notes
friends_online_presence
friends_photo_video_tags
friends_photos
friends_relationship_details
friends_relationships
friends_religion_politics
friends_status
friends_subscriptions
friends_videos
friends_website
friends_work_history
Hope it helps :)
I've been wrestling with this all day myself and I believe I have figured it out, nowhere in facebook documentation (that I have found) is this clear. And I don't believe the other answers actually answered your question, it looks like you requested permissions correctly. Anyway, to request the information you are looking for, ping the api like this:
https://graph.facebook.com/userid/friends?fields=work&access_token=ACCESSTOKENHERE
This will return you all the friends' info in one long JSON response.
It is a little confusing because the permissions you are asking for are not the same thing you need to query the API.
The query above will return the friends' ids with work history. You can add commas to the fields parameter to include additional info like name, but then the API calls/responses end up taking a long time.
http://developers.facebook.com/docs/reference/api/user/
you can get all the fields mentioned here .To get work you need to have user_work_history or friends_work_history permission
in the link it is mentioned what permissions to obtain before you get the info and another thing that user has to allow your application,this will make your app to get the informations.
From this answer to another question: a call to 'me/friends?fields=work' worked for me!
I'd suggest that you go to http://developers.facebook.com/docs/reference/api/user/ like most of the others are suggesting but as a general tip, use the friends_education_history as a way to get the friend's history.
P.S: Minor spelling error in your original question that should be edited. "education_histroy." = education_history
in the second line of your main paragraph.
You can use this code you will get name, profile picture, ID of your friends.
FB.api('/me/taggable_friends', function(response) {
for (var i = 0; i < friend_data.length; i++) {
results += ''+friend_data[i].name;
}
});
Before that in your developer account created app-> go to tools and support->graph API explorer-> click Get Token. In that window click user_tagged_places and click Get Access Token. You will get your friends list.