Looking for timeline of a twitter user using twitter4j 3.03 - twitter

I am trying to retrieve the timeline of a twitter user using twitter4j. I was able to do this using version 2.6 but now I upgraded to 3.03 and started getting authenticaton error from twitter.
401:Authentication credentials (https://dev.twitter.com/pages/auth)
were missing or incorrect. Ensure that you have set valid consumer
key/secret, access token/secret, and the system clock is in sync.
message - Could not authenticate you code - 32
This is how I retrieve a twitter object
TwitterFactory twitterFactory = new TwitterFactory(
new ConfigurationBuilder().setDebugEnabled(true).
setOAuthConsumerKey(oAuthConsumerKey).
setOAuthConsumerSecret(oAuthConsumerSecret).
setJSONStoreEnabled(true).
build());
twitter = twitterFactory.getInstance();
twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
When I retrieve a twitter object like this and try to get a different user than the authenticated user I got an authentication error. Here is the code for retrieving the user:
user = twitter.showUser(userName);
Before the upgrade I was able to retrieve any user who has a public profile, but now I can't retrieve any user other than the authenticated user itself. Am I doing smtg wrong here, Do I need to get permission from the user to lookup for his timeline, which I don't believe because when I use oauth tool of twitter I am able to retrieve the user without getting any permission from the user.
I am using twitter4j version 3.03.

Apparently old api was accepting userNames starting with "#" whereas the new version just throws this strange error. After removing the "#" from the searched user name everything worked without any problem.

Related

How to get followers list from Twitter?

I am trying to call following Twitter's API to get a list of followers for a user.
http://api.twitter.com/1.1/followers/ids.json?cursor=-1&screen_name=username
And I am getting this error message in response.
{
code = 215;
message = "Bad Authentication data";
}
I can't seem to find the documentation related to this error code. Anyone has any idea about this error?
Your request lacks authentication data. I got that error when I simply clicked on http://api.twitter.com/1.1/followers/ids.json?cursor=-1&screen_name=username. This is not the way to access twitter API.
Create a Twitter app from https://apps.twitter.com/. Then, try using a Twitter API Library to access REST API. If you are comfortable with using ruby apps on command line interface check out https://github.com/sferik/t. Set it up and then try t followers [USER] for listing all followers of USER.
You will have to use OAuth. More info can be found on Twitter website. Here: https://dev.twitter.com/oauth
This error is coming because your Twitter developers account is not approved. Now-a-days you can't make app without getting your developers account approved from Twitter.
To make an app, you need to contact Twitter and apply for developers account. If you are lucky engough, you will get approval although this process may take months.
If you just need the data, go for third party services like followersanalysis[dot]com, birdsonganalytics[dot]com

FacebookLogin loginWithReadPermissions does not request any new permissions

Ive previously requested public_profile, user_friends, and email which Facebook will let you use pretty freely in my Swift iOS app but now I'm trying to update the app to request new permissions with loginWithReadPermissions but when it transfers to the login page it just says that I've already granted my app permission and doesn't request the new permissions. Querying the results shows no granted or denied permissions and looking at the Graph Explorer API on the Facebook Developer site shows the same. So I'm looking for suggestions on why my app might not be sending the updated request to the server.
I should note that I'm utilizing the AWS iOS Mobile SDK. I found another answer that overwrites the default Facebook sign in provider to add new permissions to the request but this has the same result.
Also in my output Im seeing the following string which contains all the permissions Im trying to request which makes me think that the request is going out but something else is happening
scope=email%2Cuser_birthday%2Cuser_hometown%2Cuser_friends%2Cpublic_profile%2Cuser_about_me

.NET - Update status (tweet) to Twitter without PIN or real Callback url?

I'm trying to write an app that can tweet using an 'application' I registered with Twitter. I am using TweetSharp and have tried to get my TwitterService set up as follows:
public Twitter(string consumerKey, string consumerSecret)
{
this.twitterService = new TwitterService(consumerKey, consumerSecret);
OAuthRequestToken oAuthRequestToken = this.twitterService.GetRequestToken();
Uri uri = this.twitterService.GetAuthorizationUri(oAuthRequestToken);
Process.Start(uri.ToString());
OAuthAccessToken oAuthAccessToken =
this.twitterService.GetAccessToken(oAuthRequestToken);
this.twitterService
.AuthenticateWith(oAuthAccessToken.Token, oAuthAccessToken.TokenSecret);
}
It gets to the OAuthAccessToken line and then takes me to the Authorize [my app] to use your account? page on the Twitter website. Before I specified a phony callback url, it displayed a page with the PIN that my user is supposed to enter when I clicked the 'Authorize app' button. Then when I added a phony callback url, it would attempt to go to that page and my code would blow to smithereens with the following error:
The remote server returned an error: (401) Unauthorized.
What I want to know is: can I tweet programatically without the need to enter a PIN or have a legitimate callback url?
Tweets must be sent in the context of a user. (Ref: POST statuses/update.) Therefore, your app must get the user's authorization (an OAuth access token) in order to send a Tweet. Since you can't get an access token without using either PIN-based authentication or a callback URL, I'm afraid that what you are asking simply cannot be done.
If, however, you just want to avoid prompting your users to enter the PIN each time they start your app, then the answer is simple: Once you have a valid access token, save it somewhere (e.g. to a file) and then reload it next time your app runs. For my WinForms app, I use .NET's built-in per-user Settings mechanism to store the Access Token and Access Token Secret. A web app would probably be better off using a database or similar to persist access tokens.
Note: If you do this, you'll also need to check the validity of the stored access token, and repeat the authorization process if it's no longer valid. The Twitter API documentation suggests using the GET account/verify_credentials method for this purpose.

iOS facebook SDK 3 > Get the signed request

I try to get the signed request to login the user via a webservice but I only have access to the accessToken on FBSession.
I saw this link
Facebook Signed Request for iOS (HMAC SHA256)
who shows how to convert the signed_request but doesn't show how to get it.
Need help :)
If I undersand you right you want your app to login and then make a call to a server where you need to check the users credential again.
I used this tutorial for the authentication.
Then when I call the server I send the accessToken property as a parameter to check the users credentials on the server. You can get the token value like this:
FBSession.activeSession.accessToken
On the server side you can then set the access token to the value you got from the app.
I compiled a gist that generates a signed request which you can then use to authenticate a user on your server without having to query the graph API.
You can find it here: https://gist.github.com/3962188
You can find the original question I compiled it for here: Facebook iOS SDK to return a signed request object upon login
Please note that most of the code is simply a compilation of existing open source code, but I haven't seen any fully working implementation like this anywhere.

Why is the access token that I pass to appEngine from iOS invalid?

I am working on an iPhone game that maintains a leaderboard and some social interaction through a backend that I built in Google App Engine. The user can log in through facebook in the iPhone app. The app sends some user details including the access token to my Google App Engine app through an HTTP post.
The handler that receives the request tries to use the access token to retrieve the users friends. I am using the pythonforfacebook SDK (which I have had success with previously) which is on Github here:
https://github.com/pythonforfacebook/facebook-sdk
The relevant python code in my GAE app is as follows:
def post(self):
at = self.request.get('at')
user = User.get_by_key_name(uid)
if not user: #create previously unknown user
logging.info('Entered unknown user code')
logging.info(at)
logging.info(type(at))
graph = facebook.GraphAPI(at)
facebook_user = graph.get_object("me")
friends = graph.get_connections(facebook_user["id"], "friends")
The logging commands print what looks like a good access token and states that the type is 'Unicode'. When I copy the access token that logging.info prints to the GAE logs and paste it into the facebook access token debugger, I get the following output:
App ID: deleted for privacy but looks right
Metadata: {"sso":"iphone-safari"}
User ID: deleted for privacy but looks right
Issued: 1345405177 (10 minutes ago)
Expires: Never
Valid: True
Origin: Mobile Web Faceweb
Scopes: offline_access read_stream
I just updated my code to use the most recent posted version of pythonforfacebook but that didn't make any difference. Any ideas would be much appreciated.
Thanks,
Dessie
To get friends of the user you can do it pretty easily without the pythonforfacebook SDK.
https://graph.facebook.com/<username or ID>/friends?access_token=<your token>
That link will give you the friends of the user in JSON format. So if you import urllib2 and json you could do:
response = urllib2.urlopen(<url above>)
friendsString = response.read()
friends = json.loads(friendsString )
Then friends will be a dict containing of all the friends.

Resources