Persistent server side Facebook authentication - ruby-on-rails

I am trying to pull a public feed from the graph onto my site. I'm currently doing this with the Koala gem for Ruby on Rails.
My problem is that I can not figure out if it is possible to silently maintain authentication so as not to interrupt service. I do not want my user to be authenticated, just myself using a server side connection.
Can this be done? What am I missing?

I assume you have a Facebook app set up. To get a public page's posts, you will need to use your app access token. Note that this is different from the app id and secret specified in your app configuration on Facebook's developer site. Koala's OAuth class provides a method to get it.
Here's how to do it:
oauth = Koala::Facebook::OAuth.new Facebook::APP_ID, Facebook::SECRET
app_access_token = oauth.get_app_access_token
graph = Koala::Facebook::API.new app_access_token
graph.get_connections("depechemode", "posts")
(I'm a Depeche Mode fan.)

Do you mean, you want to pull a public page's feed and display it on your website, without your website's users needing to login to facebook? Please provide more detail.

Related

Via the api, can I force the user to login to reddit?

I am writing a Reddit client that uses OAuth to authenticate the user. One of the features I would like to implement is the ability to use multiple accounts simultaneously. This requires the user to authorize my client on each account they want to use. The problem I'm running into is that if the user is already logged into Reddit in their browser, when I pop a browser to perform the auth, it will have them authenticate my client against their currently logged in user.
Is there a way to force the user to re-enter their credentials? I would rather not have to put some kind of disclaimer on my Add Account screen that says "Please log out of Reddit in any open browser windows".
I tried opening the Reddit login page in a WebView so the request is sandboxed, and while that worked, it gives the user access to the entire login page (including all the links that navigate to elsewhere on the site). I don't mind that experience when I'm popping an external browser, but in an embedded WebView I really just want to present a username and password box along with the OAuth validation prompt.
Note: I do kind of prefer the embedded experience because it doesn't interfere with the users existing browser cookies, I just don't like how cluttered the login page is this way and I'm not sure how to prevent the user from navigating away from login. Also, for completeness, this is a UWP app, though this problem is largely technology independent.
The problem I'm running into is that if the user is already logged into Reddit in their browser, when I pop a browser to perform the auth, it will have them authenticate my client against their currently logged in user.
It may be caused by the authorization server. If so, we can not do anything in our client app.
But if it is not the server issue, in UWP, there is a WebAuthenticationBroker class witch can help you to authorize your app to access the user info from Resource server by getting a token. You can try to use the class to implement OAuth authorization. You don't need to use the in a WebView so that you can authorize your app with multiple users if you can manage all the user with the token properly in your code logic.
See the Web authentication broker topic and the sample to learn more details.

Get Twitter id with Screen Name

Hi I'm trying to get Twitter ID by Screen name..
Screen name is: KTutorials
Here is my link to get Twitter Id
https://api.twitter.com/1.1/followers/ids.json?cursor=-1&screen_name=ktutorials&count=5000
But I'm getting this error.
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
Here is my Twitter link https://twitter.com/ktutorials
Any Help?
I can see that you are using Twitter API to GET followers/ids method. GET request for this method require OAuth Signature. This means that you should have Twitter App created and if not, you should have create one here.
Subsequently, you should visit GET followers/ids documentation page, and get OAuth Signature using the "OAuth Signature Generator" located at bottom of page.
Bad Authentication data tells that you it can't do the operation due to the bad authentication.
From API V1.1, all requests should be authenticated first. So, create
an app in Twitter console and put the important keys like Access keys
and Consumer keys.
If you feel you are authenticated user, then re-generate your token and give another try!

instagram follow api error

Objective -C / iOS
I will use follow api of instagram .
set URL :https://api.instagram.com/v1/users/{userid}/relationship?access_token={access_token}
parameter string is "action=follow" ,and data sending way of post
But , it doesn't works. I received error.
meta = {
code = 400;
"error_message" = "This request requires scope=relationships, but this access token is not authorized with this scope. The user must re-authorize your application with scope=relationships to be granted write permissions.";
"error_type" = OAuthPermissionsException;
};
When i use login api of instagram , scope = relationships+likes ... data sended
How to use instagram follow api in iOS.
Instagram changed its API guidelines since mid April, 2015.
https://help.instagram.com/contact/185819881608116
The OAuth 2.0 specification allows you to specify the scope of the access you are requesting from the user. All apps have basic read access by default, but if you plan on asking for extended access such as liking, commenting, or managing friendships, you need to specify these scopes in your authorization request. Note that in order to use these extended permissions, first you need to submit your app for review. For more information on how to submit your app for review, please check out the documentation of the endpoint that you plan to use.
Hence you need to get your app reviewed by instagram first to use these extended permissions such as Likes, Comments and Relationships.
As stated in the error that you're getting, you need to have a certain permission for you to be able to perform a "follow" action. You can't just follow another account on a user's behalf without getting the proper permission first in the authentication process.
When calling the authorize api you can add a parameter called scope which specifies the permission level that your app is requesting. For example: scope=basic+relationships will allow you to read all basic user data and also follow and unfollow accounts on a user’s behalf.
This is a post request. To make post request to InstagramAPI you need to submit your application details and company details to Instagram for review. Maybe other relationship endpoints will work fine without submitting your app. Even though you are adding scope as scope=likes+relationships+comments, instagram will give you basic permissions only. For more details visit the following link https://instagram.com/developer/endpoints/relationships/#post_relationship

Facebook authentication without requesting friend list

I'd like to use Facebook OAuth authentication for a web application in a business context. What I need is a user ID and nothing else but Facebook by default always says "... will receive the following info: your friend list and email address".
Is there any way to configure Facebook or my application not to request the friend list for which I have no need to know?
By the way, I am using ASP.NET MVC but should be able to make the required adjustments to my application if someone can point me into the right direction.
If you are using Microsoft.Asp.net.Facebook like below tutorial
http://www.asp.net/mvc/tutorials/mvc-4/aspnet-mvc-facebook-birthday-app
You can set the attributes like below to get permissions for required things:
[FacebookAuthorize("email", "user_photos", "user_friends")]
if you don't need friends details remove the attribute.
[FacebookAuthorize("email", "user_photos")]

Getting Facebook Public Profile URLs

I'm building a feature in my web service to let people enter their Facebook URL into a field. Because few people know their FB user names or public profile URLs, I'd like to provide an interface to assist.
In brief: is there a way to get a list of matching users's public URLs by providing a name alone?
I have tried examining the Facebook Open Graph API; this appears to require knowing the user ID of the person, or the user ID.
I have tried using Mechanize and Nokogiri to automate the process, logging into Facebook as myself and accessing the search feature (http://facebooks.com/search/results.php?q=Person%20Name), but it's not returning any data when attempted this way. I suspect Facebook is using some kind of joojoo to keep me out that way.
Anyone have any suggestions?
With a valid access token, you should be able to query https://graph.facebook.com/me/ to get their ID, name, and public URL (Here's an example using the Graph API Explorer).
There's a search endpoint in the graph API, unfortunately it requires valid user access token.
https://graph.facebook.com/search?q=<name>&type=user&access_token=<user access token>
However it could be yours even, by getting a long living access token it would work for 60 at most, but it's probably a bad idea.
The type could be user, post, event, group, page.
Having done additional research, it appears to not be possible to get a user's public profile page without their permission. Hooray for Facebook privacy settings, I guess.
However, getting an access token is easier than I imagined it would be. Facebook offers an example on their site for getting user permission to access their account, implemented entirely on the client side. Nice and easy; the access token is returned in the URL.
The only downside here is you have to create an application on Facebook, at http://developers.facebook.com/apps. For my purposes, the "Website with Facebook Login" was the application type.
From that point, you can use that token to interrogate the Graph API with ease, as both Warpling and complex857 have suggested.

Resources