I'm writing an android app for Brightkite and I would like to use their oAuth service to authorise the application.
I've successfully got the application to load up a webview to the site, however when I try log in, it instead invokes the browser on login and takes me to the mobile site.
Within my view, I have set the UA as a desktop browser, so if I can keep it within this it may work. Below are my two classes for the app, and any help would be appreciated.
Using java Syntax Highlighting
- package org.ifies.brightroid;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import java.net.URL;
- import net.oauth.OAuth;
- import net.oauth.OAuthAccessor;
- import net.oauth.OAuthConsumer;
- import net.oauth.OAuthMessage;
- import net.oauth.OAuthServiceProvider;
- import net.oauth.client.OAuthClient;
- import net.oauth.client.httpclient4.HttpClient4;
- import org.ifies.brightroid.oAuthAuth;
- public class BrightRoid extends Activity {
- /** Called when the activity is first created. */
- private static final String BRIGHTKITE_AUTHORIZE_URL = "http://brightkite.com/oauth/authorize?oauth_token=";
- private static final String OAUTH_REQUEST = "http://brightkite.com/oauth/request_token";
- private static final String OAUTH_AUTHORIZE = "http://brightkite.com/oauth/authorize";
- private static final String OAUTH_ACCESS = "http://brightkite.com/oauth/access_token";
- private static String CONSUMER_KEY = "";
- private static String CONSUMER_SECRET = "";
- private OAuthClient httpClient;
- private static Button exitButton;
- private static Button loginButton;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.loginscreen);
- exitButton = (Button) findViewById(R.id.button_exit);
- exitButton.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- loginButton = (Button) findViewById(R.id.button_login);
- loginButton.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- try {
- doLoginAuth();
- } catch (Exception e) {
- Log.e("Error", e.getMessage().toString());
- }
- }
- });
- }
- @Override
- protected void onResume() {
- super.onResume();
- }
- @Override
- protected void onPause() {
- super.onPause();
- }
- public void doLoginAuth() throws Exception {
- final OAuthServiceProvider provider = new OAuthServiceProvider(
- OAUTH_REQUEST,
- OAUTH_AUTHORIZE,
- OAUTH_ACCESS);
- final OAuthConsumer consumer = new OAuthConsumer(null // callback URL
- , CONSUMER_KEY // consumer key
- , CONSUMER_SECRET // consumer secret
- , provider);
- final OAuthAccessor accessor = new OAuthAccessor(consumer);
- httpClient = new OAuthClient(new HttpClient4() {
- public HttpClient4 getHttpClient(URL server) {
- return new HttpClient4();
- }
- });
- try {
- httpClient.getRequestToken(accessor);
- // manually set the access token to the request token...not sure
- // why
- accessor.accessToken = accessor.requestToken;
- if (accessor.accessToken != "") {
- Intent i = new Intent(BrightRoid.this, oAuthAuth.class);
- i.putExtra("BRIGHTKITE_AUTHORIZE_URL", BRIGHTKITE_AUTHORIZE_URL);
- i.putExtra("request_token", accessor.requestToken.toString());
- BrightRoid.this.startActivity(i);
- }
- } catch (Exception e) {
- Log.e("oAuth Error", e.getMessage().toString());
- }
- }
- }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- package org.ifies.brightroid;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.webkit.WebView;
- import android.webkit.WebSettings;
- import android.widget.Button;
- import android.util.Log;
- public class oAuthAuth extends Activity {
- private String url;
- private String request_token;
- private Button closeAuth;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.oauth_auth);
- closeAuth = (Button) findViewById(R.id.button_close_auth);
- closeAuth.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- Bundle extras = getIntent().getExtras();
- if(extras != null) {
- url = (String) extras.getString("BRIGHTKITE_AUTHORIZE_URL");
- request_token = (String) extras.getString("request_token");
- }
- WebView wv;
- wv = (WebView) findViewById(R.id.wv1);
- WebSettings wv_settings = (WebSettings) wv.getSettings();
- wv_settings.setSavePassword(false);
- wv_settings.setSaveFormData(false);
- wv_settings.setJavaScriptEnabled(true);
- wv_settings.setSupportZoom(true);
- wv_settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
- wv_settings.setUserAgent(1);
- wv_settings.setSupportMultipleWindows(false);
- String request_url = url + request_token;
- Log.i("oAuth Request URL", request_url);
- wv.loadUrl(request_url);
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

