Hi there,

Thanks - your examples are a little clearer, but I'm still having
issues at the same point.

Here is my new code:
package org.ifies.brightroid;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.util.Log;
import android.content.DialogInterface;
import android.content.Intent;

import org.ifies.brightroid.oauth.*;

public class AppSettings extends Activity {
        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 static Button button_auth;
        private static Button button_back_from_settings;

        public oAuthClient oauth_client;

        @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setNoTitle();
        setContentView(R.layout.app_settings);

        button_auth = (Button) findViewById(R.id.button_auth);
        button_auth.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View v) {
                        try {
                                doLoginAuth();
                        } catch (Exception e) {
                                Log.e("Auth Error", e.getMessage().toString());
                        }
                }
        });
        button_back_from_settings = (Button) findViewById
(R.id.button_back_from_settings);
        button_back_from_settings.setOnClickListener(new
View.OnClickListener(){
                        @Override
                        public void onClick(View v) {
                                finish();
                        }
        });
        }

        public void setNoTitle() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    public void doLoginAuth() throws Exception {

        try{
                ClientSettings oauth_client_settings = new ClientSettings();
                oauth_client_settings.setOAuthAccessTokenUrl(OAUTH_ACCESS);
                oauth_client_settings.setOAuthAuthorizeUrl(OAUTH_AUTHORIZE);
                oauth_client_settings.setOAuthRequestTokenUrl(OAUTH_REQUEST);
                oauth_client_settings.setConsumerToken(new Token(CONSUMER_KEY,
CONSUMER_SECRET));

                oauth_client = new oAuthClient();
                oauth_client.setClientSettings(oauth_client_settings);
                String auth_url = oauth_client.getUserAuthorizationUrl();

                Intent auth_intent = new Intent(AppSettings.this,
oAuthRequest.class);
                        auth_intent.putExtra("BRIGHTKITE_AUTHORIZE_URL", 
auth_url);
                        auth_intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                        AppSettings.this.startActivity(auth_intent);
                } catch (Exception e) {
                        Log.e("oAuth Error", e.getMessage().toString());
                }
    }

}

Here I am using some of your code to make a simple library for oAuth.
My second class is this:

package org.ifies.brightroid;

import java.util.Collection;

import net.oauth.OAuthMessage;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.util.Log;
import android.content.Intent;

import org.ifies.brightroid.AppSettings;
import org.ifies.brightroid.oauth.*;

public class oAuthRequest extends Activity {

        private String url;
        private String request_token;

        private Button button_close_auth;
        public WebView webView;

        @Override
        public void onCreate(Bundle savedInstanceState) {
                Log.i("Activity", "Yea, This has been invoked!");
        super.onCreate(savedInstanceState);

        setContentView(R.layout.oauth_request);

        button_close_auth = (Button) findViewById
(R.id.button_close_auth);
        button_close_auth.setOnClickListener(new View.OnClickListener()
{
                        @Override
                        public void onClick(View v) {

                        oAuthClient oauth_client = new 
AppSettings().oauth_client;

                        try {
                                oauth_client.fetchAccessToken();
                                Token access_token = 
oauth_client.getClientSettings
().getUserSpecificAccessToken();
                                Log.i("Public Token", 
access_token.getPublicToken());
                                finish();
                        } catch (Exception e) {
                                Log.e("Access Token Error", 
e.getMessage().toString());
                                finish();
                        }

                        }
        });

        Bundle extras = getIntent().getExtras();
                if(extras != null) {
                        url = (String) 
extras.getString("BRIGHTKITE_AUTHORIZE_URL");
                }

        webView = (WebView) findViewById(R.id.wv1);
        webView.loadUrl(url);
        WebViewClient webViewClient = new WebViewClient();
        webViewClient.shouldOverrideUrlLoading(webView, url);

        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setSavePassword(false);
        webView.getSettings().setSaveFormData(false);
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.getSettings().setUserAgent(1);
        webView.getSettings().setSupportMultipleWindows(false);
        webView.setWebViewClient(webViewClient);
        Log.i("oAuth Request URL", url);
        }
}

As you can see, the user gets to auth the app in the web view, then I
want to get the access token so I can save this, however it always
seems to crash the app, even in a try/catch block.  Any help would be
much appreciated!

On Jan 11, 9:22 pm, "Sean Sullivan" <[email protected]> wrote:
> I've written two Android applications that use OAuth.  The first app
> connects to Fire Eagle via OAuth:
>    http://code.google.com/p/jfireeagle/wiki/Android
>
> The second app connects to PortableContacts providers:
>
>    http://code.google.com/p/jpoco/wiki/Android
>
> The source code is in SVN on code.google.com
>
> Sean
>
> On Sun, Jan 11, 2009 at 10:10 PM, Tane Piper 
> <[email protected]>wrote:
>
>
>
> > Hi folks,
>
> > I'm writing an Android app for Brightkite using the oAuth API and I've
> > hit a bit a a stopping point.  I've had a look at the example for the
> > Desktop application and I can't work out what it's doing with
> > overwriting the accessor.  I've pasted the first part of the
> > authorisation below, which invokes a webview to allow the app to be
> > authed with the request token:
>
> > package org.ifies.brightroid;
>
> > import java.net.URL;
>
> > import net.oauth.OAuthAccessor;
> > import net.oauth.OAuthConsumer;
> > import net.oauth.OAuthServiceProvider;
> > import net.oauth.client.OAuthClient;
> > import net.oauth.client.httpclient4.HttpClient4;
> > import android.app.Activity;
> > import android.app.AlertDialog;
> > import android.os.Bundle;
> > import android.view.View;
> > import android.view.Window;
> > import android.widget.Button;
> > import android.util.Log;
> > import android.content.DialogInterface;
> > import android.content.Intent;
>
> > public class AppSettings extends Activity {
> >        private static final String OAUTH_REQUEST = "http://brightkite.com/
> > oauth/request_token <http://brightkite.com/oauth/request_token>";
> >        private static final String OAUTH_AUTHORIZE = "
> >http://brightkite.com/
> > oauth/authorize <http://brightkite.com/oauth/authorize>";
> >        private static final String OAUTH_ACCESS = "http://brightkite.com/
> > oauth/access_token <http://brightkite.com/oauth/access_token>";
> >        private static final String BRIGHTKITE_AUTHORIZE_URL = "http://
> > brightkite.com/oauth/authorize?oauth_token=";
> >        private static String CONSUMER_KEY = "";
> >        private static String CONSUMER_SECRET = "";
>
> >        public OAuthClient httpClient;
> >        public OAuthAccessor accessor;
> >        public OAuthServiceProvider provider;
> >        public OAuthConsumer consumer;
>
> >        private BrightRoid br_app;
>
> >        private static Button button_auth;
> >        private static Button button_back_from_settings;
>
> >       �...@override
> >        public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
> >        setNoTitle();
> >        setContentView(R.layout.app_settings);
>
> >        br_app = new BrightRoid();
>
> >        button_auth = (Button) findViewById(R.id.button_auth);
> >        button_auth.setOnClickListener(new View.OnClickListener(){
> >               �...@override
> >                public void onClick(View v) {
> >                        try {
> >                                Log.i("Application", "We get to try very
> > hard!");
> >                                doLoginAuth();
> >                        } catch (Exception e) {
> >                                Log.e("Auth Error",
> > e.getMessage().toString());
> >                        }
> >                }
> >        });
> >        button_back_from_settings = (Button) findViewById
> > (R.id.button_back_from_settings);
> >        button_back_from_settings.setOnClickListener(new
> > View.OnClickListener(){
> >                       �...@override
> >                        public void onClick(View v) {
> >                                finish();
> >                        }
> >        });
> >        }
>
> >        public void setNoTitle() {
> >        requestWindowFeature(Window.FEATURE_NO_TITLE);
> >    }
>
> >    public void doLoginAuth() throws Exception {
> >        Log.i("Application", "We get into the function");
> >        provider = new OAuthServiceProvider(
> >                        OAUTH_REQUEST,
> >                        OAUTH_AUTHORIZE,
> >                        OAUTH_ACCESS);
> >        consumer = new OAuthConsumer(null // callback URL
> >                , CONSUMER_KEY // consumer key
> >                , CONSUMER_SECRET // consumer secret
> >                , provider);
> >        accessor = new OAuthAccessor(consumer);
> >        Log.i("Application", "oAuth stuff 1 done");
> >        httpClient = new OAuthClient(new HttpClient4() {
>
> >                       �...@suppresswarnings("unused")
> >                        public HttpClient4 getHttpClient(URL server) {
> >                                return new HttpClient4();
> >                        }
> >                });
>
> >        try {
> >                Log.i("Application", "Were going to try again");
> >                        httpClient.getRequestToken(accessor);
> >                        Log.i("Application", "Http Got token");
> >                        // manually set the access token to the request
> > token...not sure
> >                        // why
> >                        accessor.accessToken = accessor.requestToken;
> >                        Log.i("Application", "Set Token");
> >                        //br_app.app_database.addRow("String",
> > "accessToken",
> > accessor.accessToken.toString());
> >                        //Log.i("Application", "DB Dave Done");
> >                        if (accessor.accessToken != "") {
> >                                Log.i("Application", "we have a token");
> >                                Intent auth_intent = new
> > Intent(AppSettings.this,
> > oAuthRequest.class);
>
> >  auth_intent.putExtra("BRIGHTKITE_AUTHORIZE_URL",
> > BRIGHTKITE_AUTHORIZE_URL);
> >                                auth_intent.putExtra("request_token",
> > accessor.requestToken.toString());
>
> >  auth_intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
> >                                Log.i("Application", "We get to invoking the
> > activity");
> >                                AppSettings.this.startActivity(auth_intent);
> >                        }
>
> >                } catch (Exception e) {
> >                        Log.e("oAuth Error", e.getMessage().toString());
> >                }
> >    }
>
> > }
>
> > After that, and the user closes the window, I want to pass this on to
> > a new intent that exchange the key for the auth key, but the only
> > example I can find is here:  http://awalkingcity.com/blog/?p=13
>
> > However, in this example, it uses the deprecated invoke method.  Can
> > anyone help me out with getting this part sorted out?
>
> > Thanks,
> > Tane
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"OAuth" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/oauth?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to