how to get screen name of twitter using codebird js - twitter

1.2.GA and Android Emulator to run my Apps. AM using codebird to authorize my app in twitter and I got access token and using it how to get screen name or userid to fetch tweets of the user?

When the user returns from the authentication screen, you need to trade
the obtained request token for an access token, using the OAuth verifier.
As discussed in the README section ‘Usage example,’ you use a call to
oauth/access_token to do that.
The API reply to this method call tells you details about the user that just logged in.
These details contain the user ID and the screen name.
Take a look at the returned data as follows:
{
oauth_token: "14648265-rPn8EJwfB**********************",
oauth_token_secret: "agvf3L3**************************",
user_id: 14648265,
screen_name: "myx",
httpstatus: 200
}
If you need to get more details, such as the user’s latest tweet,
you should fetch the complete User Entity. The simplest way to get the
user entity of the currently authenticated user is to use the
account/verify_credentials API method. In Codebird, it works like this:
cb.__call(
"account_verifyCredentials",
{},
function (reply) {
console.log(reply);
}
);
I suggest to cache the User Entity after obtaining it, as the
account/verify_credentials method is rate-limited by 15 calls per 15 minutes.

Related

Ruby on Rails view Facebook Event without user login

I'm putting together a website which displays Facebook events using Ruby on Rails and Koala.
I can display an event just fine if I do the following:
graph = Koala::Facebook::API.new(auth_token)
fb_event = graph.get_object(some_event_id)
But as soon as I change the first line to:
graph = Koala::Facebook::API.new(auth_token)
Ie, without the auth_token, I get an error--> type: OAuthException, code: 104, message: An access token is required to request this resource. [HTTP 400]
I don't want the user to have to be logged in in order to view the event. I know that I don't have to be logged into Facebook to view the event, so I'm sure there must be way to get the event without having to have the user be logged in. Any ideas?
Using WizKid's comment to get me there:
I went to https://developers.facebook.com/tools/access_token/
I then used my app's "User Token"

How to access basic user information for "Private Users" on Instagram API?

I am writing an application and need to read basic Instagram user info such as username, #posts, #followers and etc. This works well for public users but for private users returns:
{
"meta":
{
"code":400,
"error_message":"you cannot view this resource",
"error_type":"APINotAllowedError"
}
}
Let's say I am signed in as user A, and we want to show information from User B which is private to user A (user B also authorized my application to access it's basic info). I am using the following end point to read user B information:
https://api.instagram.com/v1/users/<userB_ID>/?access_token=<myAccessToken>
Am I missing something? or should I use different end point?
Update (Solution #1)
It seems one solution to fix this is to use Query end point. I was trying to manage all my work with Instagram user IDs (not usernames) but it seems I have to use usernames for the query. Is there a way to use query with user ID?
Here is what it looks like:
https://api.instagram.com/v1/users/search?q=<UserB_Username>&client_id=<myClientID>
if <myAccessToken> is to get user A's info, you can't get User B's info with it. If you have a backend to this app, then you can store different access tokens for each user, and make the call with the appropriate access token, and feed the info to the app through your own API.

Getting Facebook Page's Ratings

I am looking to pull a public Facebook page's ratings into a Ruby on Rails app.
Essentially what I'm looking to do is run a rake task as a cron job that looks for new reviews on one particular Facebook page (the page I need will not change) and pulls them into the app. I've explored Facebook's API and the Koala gem and can't get to the page data. I'm just not sure how I can get an access token outside a browser. In addition, if I were to get the access token, it doesn't seem I can get to the ratings data without being the owner of the page.
One route I took was to send a simple GET request to the page. Something like https://graph.facebook.com/{page-id} works fine, but https://graph.facebook.com/{page-id}/ratings throws the following:
{
"error": {
"message": "(#210) Subject must be a page.",
"type": "OAuthException",
"code": 210
}
}
What is the simplest way to get to this data?
As mentioned in the question's comments, I needed to be authenticated as a Facebook user with admin access to the Facebook Page of interest because I need to get a token from that.
After getting access to the page, I accomplished the API call via the Koala gem. I initialized Koala with the app:
config/initializers/facebook.rb
$facebook = Koala::Facebook::OAuth.new(
"my_facebook_app_id",
"my_facebook_secret",
"my_facebook_redirect_url"
)
Since I only needed to get the token for one user in one scenario, I did so via the admin side of my app, in my facebook_controller.
In this controller action, I look for the code parameter in the route. If we don't find it, we send to the authorization url, otherwise we process and store the Facebook user token in the User model in a pre-determined and predictable record.
app/controllers/admin/facebook_controller.rb
def auth
if params[:code].present?
code = params[:code]
token = $facebook.get_access_token_info(code)
User.find_by_email('admin#example.com').update(
:fb_access_token => token['access_token'],
:fb_token_expires => token['expires'].to_i.seconds.from_now
)
redirect_to admin_dashboard_path
else
redirect_to $facebook.url_for_oauth_code(:permissions => "manage_pages")
end
end
Once I have an active token, I can acquire the page token like so:
user = User.find_by_email('admin#example.com')
user_graph = Koala::Facebook::GraphAPI.new(user.fb_access_token)
accounts = user_graph.get_connections('me', 'accounts')
page_token = accounts[0]['access_token']
page_graph = Koala::Facebook::API.new(page_token)
ratings = page_graph.get_connection('me', 'ratings')
At this point, I have the collection of ratings objects stored in the ratings variable. I can do whatever I need with these ratings at this point.
Note: In this particular case, I new the Facebook Page was the first account in the array of user accounts. This took some trial and error, but can be accomplished by iterating over the user accounts array (in this case, stored in accounts) if you can't predict the index of the desired account.
It seems to be a bug of Facebook Graph API. I have exactly the same problem.
I can get lists of all other objects but I do get an error when requesting /{page-id}/ratings. The JSON payload returned by Facebook Graph API is the following:
{
"error": {
"message": "(#210) Subject must be a page.",
"type": "OAuthException",
"code": 210
}
}

How can I get all tweets relating to a specific user in Twitter?

I am new to the Twitter API and I'm having an issue with the user_timeline API.
I am using the following REST query:
https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=twitterapi&count=50
which is provides the user's timeline data, however it only gives the user's tweets; I want all tweets by and about the user (i.e. the user's tweets, and mentions of the user by the user's followers).
Thanks in advance!
You can access this by searching for the user's # handle. This will return tweets which mention #user and also tweets by #user.
Twitter API - Search
--
I've no experience about formatting for JSON calls but the following should be enough:
https://api.twitter.com/1.1/search/tweets.json?q=%40ataulm
The %40 is for the # symbol, and ataulm is the user name you wish to query. See the page linked for default values to the other parameters - this will, for example, only return 15 tweets per "page" (not sure what a page refers to), but can be set to a maximum of 100 per page, using the count parameter.
"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser.'&count=500'
BUt it is giving only 200 records.

Rails 3 Linkedin API gem

I'm trying to set up the linkedin api in a rails 3 app using the linkedin gem. I don't want the user to have to authenticate my app in order for the API to get their info. I only need one piece of their public profile (the headline). So, maybe I should just be using xml or json to pull this off (not exactly sure how to get that with linkedin either).
I have the following in a helper so that I can call linkedin_header() in a loop of users. I only have 'client' as the last line of the following code while debugging. It outputs as expected (#). It seems like I am only a step away from success. How can I access a given users headline? I have tried using "client = client.profile(:url => 'linkedin_user_url')", but that return "Call must be made on behalf of a member".
def linkedin_header(account_user)
user = User.find(account_user)
account = Account.where(:user_id => user, :external_id => 1)
api_key = 'aaaaaaaa'
api_secret = 'bbbbbbbb'
client = LinkedIn::Client.new(api_key, api_secret)
rtoken = client.request_token.token # this returns correctly
rsecret = client.request_token.secret # this returns correctly
client
# client = client.profile(:url => 'linkedin_user_url')
end
So, I guess I have two questions. Is my request (public headline of any user) too simple for the above...should I be using XML or JSON. And, if Im close...can I make the API work for me without the user having to authenticate via linkedin.
Based off of what I read from the LinkedIn API reference (http://developer.linkedin.com/documents/authentication)
You have to make requests to their API only after being authenticated. (Using OAuth Keys) Rather than just grabbing the publicly available information.
It seems like since you want a small piece of information (the public headline of any user) you'd want some sort of implementation like Facebook's OpenGraph. After looking around on LinkedIn, I don't see any sort of public implementation like that.
I would suggest checking out this gem:
https://github.com/yatishmehta27/linkedin-scraper
It seems to be the type of solution you're looking for.

Resources