I was working with twitter APIs and I am able to get specific user's timeline (tweets) without making the end user to login.
How can I do this in facebook? I don't want my user to login to facebook. I just need some feeds from users/pages which are publicly shared.
Does facebook allows this? How to do it? Any links
I don't know about Android but For Facebook API, I managed to get users / pages feed (public only) using the graph for a small project I was working on, this snippet might
help you
<?php
$pageContent = file_get_contents('https://graph.facebook.com/USER_ID/posts?fields=id,name&limit=1&access_token=ACCESS_TOKEN HERE');
// You can use your app token
$parsedJson = json_decode($pageContent); // decode JSON
echo $id = $parsedJson->data[0]->id; // this echos only the latest post ID
?>
So as you see, the code above requests Facebook graph and returns only post (latest one) from the user feed (because I limited it &limit=1) that code is working for me and might works for your needs
Related
I am currently working on implementing a mobile app for our site that uses Ruby on Rails and Devise. The idea here is, at first, create a mobile login form that on successful login opens a web frame that is authenticated and allows the normal use of the (mobile optimised) site. Theoretically that should be possible.
I am having trouble with the following issues:
How do you get the pure session key for the user session via a json request? What methods can be used to manually generate it from devise, something that the sign_in(:user, user) method does?
Is it even possible to take that key and put it into the browser cookie the way it normally happens in devise, but on the mobile side?
I know that this is not the standard method of making mobile applications for the site, but I believe it should be possible.
You might want to consider using Devise Token Auth and treating your mobile application like just another webapp that requests permission from your main site. DTA is particularly nice since it takes care of managing the session tokens (renewing/expiring) and passing them onto the app requiring access. The issue is overriding your session controllers so that it automatically logs in after you already log in on the mobile app (or just rewriting your log in so it occurs in conjunction with the Rails site, rather than before). Considering you're already using Devise, this may also be more refactoring than you'd like.
If you want to put your authentication form on the mobile UI and pass the credentials over to the web frame, you need a way to pass data from the mobile app to the web frame.
How you accomplish this depends on what platform you're building on. I'm not really a mobile developer so I don't know for certain how difficult / easy these options are:
When opening the web frame, instantiate it with session data
Find a way to call methods on the client from the web frame. Something like getSessionData.
You could generate a fingerprint for the web frame, have the mobile UI send this data to the server, and then have the web frame authenticate with the server by sending the fingerprint.
Again, I'm not entirely sure how possible all these options are.
You should use token authorization and Android deep linking. It will allow you to login in the web browser and send a token to your app via deep linking.
OK, so I decided to make a webframe solution as follows, basically you post the login and password to a certain sign_in method specially designed to generate one-time sign in tokens for the application. You need two methods in the system to do that:
routes.rb
devise_scope :user do
get "sign_in_with_token/:token" => "sessions#sign_in_with_token"
post "get_login_token" => "sessions#get_login_token"
end
sessions_controller.rb (don't forget to add the method that increases the failed_sign_in_count on wrong password, otherwise that can allow brute force attacks)
def get_login_token
user = User.find_by_email(sign_in_params["login"])
password = sign_in_params["password"]
if user and user.valid_password?(password)
token = SecureRandom.hex(16)
user.update_attribute(:authentication_token, token)
render json: {token: token}, status: 200
else
render json: {error: "error"}, status: 403
end
end
and the method to sign in with that token
def sign_in_with_token
#user = User.where(authentication_token: params[:token], email: Base64.decode64(params[:email])).first
if #user
#user.update_attribute(:authentication_token, nil)
sign_in(#user, bypass: true)
end
redirect_to '/' # or user_root_url
end
That way the mobile app will work like this:
use the generic web frame to send ajax requests to the server and get that token for the user email if password is correct.
make a /sign_in_with_token/#{token from ajax}?email=#{base46 encoded email} link inside the app.
open that link inside the web frame and use the app as though you were logged in normally. Now the app can save email and password locally and use that logic to get the token again for another session. Later logging in will also be able to set the app id so that push notifications can be sent.
Appreciate any feedback or criticism on this solution.
i want to get particular person public feeds to show in my application.but in response empty data value returning.without login into Facebook i have get the Facebook user public post.
Am getting response: Unsupported get request
That is impossible, you can only get access to the feed (public or not) of someone who authorized your App with the user_posts permission. You could use an Extended User Token that is valid for 60 days to read the feed, but in general you are not supposed to show user feeds on an external website. Better use a Page for that, with an App Token or Extended Page Token - both are valid forever.
I'm thinking about how to solve the next problem:
An Android App which I want to connect to facebook, and to a Server backend(Srv).
Server backend(Srv) which I want to connect to facebook.
The server will run a task that will Get all the Friends of the user(on fb), and the user Statuses(on Fb), and store them on it.
Base assumptions:
I use android as a Mobile device
Server is GAE
Entity key in GAE is the user’s FB-id
User Entity contains:
User fb_id
User verified list(FB_ID String)=> friends of the user that have the app) // maybe use HT?
User statuses list(Status text, date, url)=> whatever I can get from a Status of a user in facebook..
Main questions:
Is the Data representation thought out? can it be better?
How do I handle a situation where two users which are connected to one another add the app at the same time- how can I avoid overlapping?
Should the device Authenticate itself, also with the GAE server?
How to Authenticate GAE with FB
Algorithm:
Android side:
User login and get access token from FB
Posting to my server(Srv) FB Token & myUserFBId // Should I use REST protocol or HTTP
POST?
Server side:
A Servlet handles the POST
{
Query FB ->for the user's friends ids(into friendList = arrayList<FBItem))
foreach FBItem item in friendList
{
//check which FB-ids are in my DB
friendEntity = getKey(item.fb_id)
if(friendEntity != null)
{
// friend exists
verifiedFriendsList.add(item.fb_id) //verifiedFriendsList is ArrayList<String>
friendEntity.getVerifiedFriendList().add(myUserFBId)
}
}
Query FB ->for the user's statuses(into statuses = arrayList<StatusItem))
add new FBEntity(myUserFBId, verifiedFriendsList, statuses) to DB }
Thanks
I have not done anything like this but I think you will need to
Ask user to authenticate your application to use FB- Read about OAuth Api of Facebook
Once your app is authenticated with sufficient permissions you can get users data as per your requirements .
Once you get the data you can process it.
Oauth on FB is what you are searching for..
I'll give you my 4 cents:
The questions that should lead you in developing the DS are: (A) On the
server side, How does the data persist? to a File? to a Database? (B) How much of that data is required to perform the calculations you want done, and how do plan to access it (for example, for an O(n) run, I wouldn't use a HashTable) (C) How does the persist / de-persist work? with an ORM? custom queries?
About concurrency, you'll have to explain what's bugging you. People sign in to SO simultaneously all the time.
3/4. Not an android developer, can't help.
I need to catch the entire list of followers in Instagram and import for my app. This is possible ?
Through the instagram api, it allows a request for followers through https://api.instagram.com/v1/users/{user-id}/followed-by. Note that authentication is required before this method will return any data.
From there, you should get a JSON response that contains all of the followers, that you can handle however you'd like within your app.
Currently on our website we enable users to login/register with their Facebook credentials using graph api. We are creating a mobile app and we want to support login with Facebook as well. I know about the Facebook Android SDK and how to retrieve the access token, my question is:
Once I have the facebook access token, how can I authenticate the user with our backend system.
One idea is to pass the access_token to my backend server and query for the user's facebook id (I don't want to pass the facebook id because someone can just spoof the request). Now using the facebook id I can then associate it with our user id and log the user in.
Would this method work, or there's another solution
The approach I described above works for well. Here's the summary:
Facebook connect through the iPhone app
Retrieve the fb access token on the phone
Send the fb access token to your Rails server
The controller that you are using will check for the fb param and query the user information
Sample of how the controller might look like
if params[:fb_access_token]
#graph = Koala::Facebook::GraphAPI.new(params[:fb_access_token])
#me = #graph.get_object("me")
if profile = Profile.find_by_facebook_uid(#me["id"])
user = profile.user
render :text => user.access_token
else
render :text => "unregistered", :status => 401 and return
end
else