pin in twitter4j - android

How can I get the pin for the twitter 4j ?
accessToken = twitter.getOAuthAccessToken(requestToken, pin);
please help..!

If you take a look to the twitter4J Code Examples, you see that the user is suppose to write the pin that he gets from the Twitter website where he will be redirected. If you want to take the pin from the URL without the user having to introduce it manually, I think the pin comes in the URL as "oauth_verifier". I did all the login with signpost because I didn't want the user having to write anything and I wasn't able to do it using only Twitter4J. Once I have the access token, I create the Twitter object from twitter4j with twitter = twitterfact.getOAuthAuthorizedInstance(consumerKey, consumerSecret,accessToken);and it works fine. This way it was much easier for me.

You need to redirect the user with a request token (that you can get from Twitter) to the twitter site, where the user enters the username/password and gets the pin back.
See e.g. https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/account/LoginActivity.java#L69 on how to direct to Twitter
and then https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/account/LoginActivity.java#L91 when the user has the pin and needs to proceed

You should be able to get away without using the PIN.
Twiiter4j DOC
Blog Post stating it is not required by Twitter

Related

How do I setup and retrieve the authorization code?

So I am using seatgeek api. The grant type is an authorisation code. Therefore you are provided with an authorization url. This authorization url will then redirect user back to the redirect url you created.This time with the code appended to it. Next you will use this code to retrieve the access token.
The authorization url is
https://seatgeek.com/oauth2?scope=offline_access,&client_id=xxxxxxxxxxxxxxxxxx
the redirect url look something like this.
https://name/oauth/fin?code=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NzEzNTMzNjUsImV4cCI6MTY3MTM1Mzk2NSwiY2xpZW50X2lkIjo5NjU2LCJ1c2VyX2lkIjozMDQ4NDIzNCwiY29kZV9jaGFsbGVuZ2UiOm51bGwsImNvZGVfY2hhbGxlbmdlX21ldGhvZCI6bnVsbH0.eVly0CYTi4DWyRQE3MerAz911LxBj6MdXcw3pAXT1Wk
looking at the above urls, the authorization url will redirect the user to https://name/oauth/fin? however the code needed is appended this time. this is the code you will need to request an access token.
I did this in my browser.However I wan to know how to set it up using retrofit and refresh it whenever it expires. Any help will be greatly appreciated.
here is the seatgeek documentation
https://partners.seatgeek.com/enterprise-client-integration/oauth if you need more info

Login via Basic Authentication and open Browser afterwards

So I want to login to a webpage which uses Basic Authentication to login.
If I send HTTP Get with the Authorization Header, I get the successful response as HTML. But afterwards, it asks me again, to login, because it didn’t remember that I’m already logged in.
So my question is:
How can I save this information, that I have already been logged in?
I know, I already asked that question before, but since no one answered any more on the other thread my last hope was to open another.
The other thread: Android doesnt notice when i do an WWW-Authenticate
EDIT:
So what i wanna do is:
Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("The Website with the Authentication")); // Here, i want to add the request header
handler.startActivity(browserIntent);
But i have no idea how, because, the only thing you can send the intent is the Url (and no request headers).
Hope this makes things clearer.
Basic authentication doesn’t save state on the server end. Every request requires that you include the login information.
What happens normally is that:
The browser makes a request for a URL, lacking any authentication.
The server returns code 401, that this URL requires basic authentication.
The browser asks (either the user, or some database of its own) for the username and password. If it asked the user for the password, the browser then stores the username/password in an internal database, keying it against this URL.
For every further request for this URL, the browser includes that username and password in the HTTP GET request.
So the basic answer is, the server doesn’t remember that you have already logged in. The browser remembers that. Since you’re writing the browser, it’s up to you to have your application remember the username/password combination for that URL. Whatever you are doing now after you receive a 401 response, you simply always do for that URL. You don’t even need to wait for the 401 response.

How to access facebook public newsfeed json/xml without authentication

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

Integrating Twitter: why can’t I post status without having to authenticate?

I want to post a simple status message to a Twitter account that's linked to my app. All users of my app will post to the same Twitter account.
I've registered my app with Twitter (according to the guidance given here: How to post a tweet from an Android app to one specific account?) and I have the necessary ConsumerKey, ConsumerSecret, AccessToken and AccessTokenSecret. I've set the account to Read & Write, and set the REQUEST type to GET.
I'm using Twitter4J and installed the twitter4j-core-3.0.3.jar into my app. The Manifest file has the required "android.permission.INTERNET". This is the code …::
AccessToken a = new AccessToken(AccessToken, AccessTokenSecret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(ConsumerKey, ConsumerSecret);
twitter.setOAuthAccessToken(a);
try
{
twitter.updateStatus("Tweet Test #1");
Log.v(TAG, "Twitter Tweet sent!");
}
catch (TwitterException e)
{
// TODO Auto-generated catch block
Log.e(TAG, "Error sending Tweet:" + e.getMessage());
}
The twitter.updateStatus("xxxxxx") call causes an exception that reports “Received authentication challenge is null” in the logcat.
I assumed I could just post, but it seems Twitter wants something more?
Can anybody offer any advice as to what I'm doing wrong?
Managed to get to the bottom of this in the end!
My particular problem was that I didn't enter a Callback URL in the Twitter Apps setup page. I'm only interested in sending tweets to my app's linked Twitter account and I already have the 4 tokens/secrets, so I don't need to get the user to authorise thier own account via my app. As such, I don't need a Callback URL.
Unfortunately, the Twitter apps page lets you leave that field blank when you request the tokens/secret, and they don't make it clear that the Callback URL is a required field. If you don't need it, you can put absolutely anything you like in there; But if you leave it blank, Twitter won't let you tweet from your app! Setting the access type to "Read & Write" is good enough just to update status, but set it to "Read, Write & Direct Messages" if you want to do more.
Some tutorials say you should set the app type to "Browser" (instead of "Desktop"), but that option seems to have disappeared from the Twitter apps page, so I guess that's no longer important.
I managed to find some very good tutorials about tweeting from an Android app (here, here and, in particular, here) which make it clear that the Callback URL is a requirement, and go on to explain very clearly how to get it to work.
Have you checked to make sure there aren't any extra whitespaces in your Twitter4J configuration file? Double-check each of your consumer.. and access.. fields just in case.

How to Login twitter using Oauth from my android application?

I am making an application which is a Twitter client. This means it connects to Twitter with OAuth. I register my application to Twitter and got all my keys, but now I do not have an idea how to connect my application with twitter. I have done some code mention below. Please help me out..
Twitter twitter=new TwitterFactory().getInstance();
twitter.setOAuthConsumer(Consumer key, Consumer secret);
RequestToken requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken=null;
Log.i("Acces Token",accessToken.getToken());
Log.i("Acces Tokensec",accessToken.getTokenSecret());
Thanks in advance.
You have two choices. Number one is easier. Number two is more difficult.
Number one just continues where you left off.
After you get a requestToken, you will need to launch a WebView and point the URL at requestToken.getAuthorizationURL(). The user will then log in and choose whether or not to allow access to his/her account. Next, if he/she hit allow, an access code will be displayed the user must copy/paste in your your own application. You will use that key with getOAuthAccessToken() (I think, I used the difficult way described later) to get the auth token that you should store somewhere permanently. At this point you are authenticated.
Number two also continues where you left off minus one detail...
twitter.getOAuthRequestToken(REDIRECT_URL).
That redirect_url must be set inside your twitter developer account first. Then follow the same steps as number one except that your webview needs to be customized. You need to use setWebViewClient() on your WebView and create a new class that extends WebViewClient. Inside the WebViewClient's onPageStarted, check if the URL starts with your return url. And then get the oauth info:
String oauth_token = uri.getQueryParameter("oauth_token");
String oauth_verifier = uri.getQueryParameter("oauth_verifier");
Use the oauth_verifier with twitter.getOAuthAccessToken() to get your token.
If the full OAuth web redirection is not convenient, you could try to use Twitter's xAuth service method to just convert a set of Twitter credentials to an OAuth access token (do that once, and save the token). Much easier on mobile applications, but you need to ask Twitter for permission to use xAuth by emailing api#twitter.com.
You could also check out another question on StackOverflow for more information on this.
If your problem is how to actually implement OAuth interactions, you might want to check out OAuth library information on Twitter and/or documentation on the library you are already using.

Categories

Resources