Hi,

Sorry to bump this again, but I've looked over the examples again, and
I still cannot see where I am going wrong!  I'm still getting an null
body back when i do:

OAuthMessage result = accessor.newRequestMessage(OAuthMessage.GET,
                "http://brightkite.com/places/search.json";,
                OAuth.newList("q", myLocation.getLatitude() + "," +
myLocation.getLongitude()));

                String result_message = result.readBodyAsString();

Any help will be much appreciated, as my app really depends on this!

On Jan 14, 12:46 am, Tane Piper <t...@digitalspaghetti.me.uk> wrote:
> Hi there,
>
> I've re-written my app a bit and have completed the token exchange
> stuff.  Now on app loadup, I check to see if there is a stored key, I
> go right into the activity.  However, whats now happening is I'm
> getting an NullPointerException on this line:
>
> Log.i("Response", result.readBodyAsString().toString());
>
> It seems I am not getting a response body.  This is the OAuthMessage I
> am sending, with some stuff changed in the values TOKEN_HASH and
> CONSUMER_KEY - but I can assure you these values are here:
>
> 01-14 00:37:15.341: INFO/Request(4818): 
> OAuthMessage(GET,http://brightkite.com/places/search.json,
> [q=55.9588086605072%2C-3.1632739305496216, oauth_token=TOKEN_HASH,
> oauth_consumer_key=CONSUMER_KEY, oauth_signature_method=HMAC-SHA1,
> oauth_timestamp=1231893434, oauth_nonce=28181971054305,
> oauth_version=1.0, oauth_signature=V6MxRdUHwUUZZBgbZjo7PW4ZQc8%3D])
>
> package org.ifies.brightroid;
>
> import java.io.IOException;
> import java.net.URISyntaxException;
> import java.util.ArrayList;
> import java.util.List;
>
> import com.google.android.maps.GeoPoint;
> import com.google.android.maps.ItemizedOverlay;
> import com.google.android.maps.MapActivity;
> import com.google.android.maps.MapController;
> import com.google.android.maps.MapView;
> import com.google.android.maps.OverlayItem;
>
> import android.content.Context;
> import android.content.Intent;
> import android.graphics.Canvas;
> import android.graphics.drawable.Drawable;
> import android.location.Criteria;
> import android.location.Location;
> import android.location.LocationListener;
> import android.location.LocationManager;
> import android.os.Bundle;
> import android.os.Handler;
> import android.util.Log;
> import android.view.Menu;
> import android.view.MenuItem;
> import android.widget.Toast;
>
> import net.oauth.OAuth;
> import net.oauth.OAuthAccessor;
> import net.oauth.OAuthConsumer;
> import net.oauth.OAuthException;
> import net.oauth.OAuthMessage;
> import net.oauth.OAuthServiceProvider;
> import net.oauth.client.OAuthClient;
> import net.oauth.client.httpclient4.HttpClient4;
>
> import org.json.JSONException;
> import org.json.JSONObject;
> import org.json.JSONTokener;
>
> public class BrightroidMap extends MapActivity {
>
>         private final OAuthServiceProvider provider = new OAuthServiceProvider
> (
>                         
> org.ifies.brightroid.oauth.Request.OAUTH_REQUEST_TOKEN_URL,
>                         
> org.ifies.brightroid.oauth.Request.OAUTH_AUTHORIZE_URL,
>                         
> org.ifies.brightroid.oauth.Request.OAUTH_ACCESS_TOKEN_URL);
>         private final OAuthConsumer consumer = new OAuthConsumer(null //
> callback URL
>             , org.ifies.brightroid.oauth.Request.CONSUMER_KEY //
> consumer key
>             , org.ifies.brightroid.oauth.Request.CONSUMER_SECRET //
> consumer secret
>             , provider);
>         private final OAuthAccessor accessor = new OAuthAccessor(consumer);
>         private final OAuthClient client = new OAuthClient(new HttpClient4
> ());
>
>         @SuppressWarnings("unchecked")
>         private class myLocationOverlay extends ItemizedOverlay {
>
>                 private List<OverlayItem> items=new ArrayList();
>                 private Drawable marker=null;
>
>                 public myLocationOverlay(Drawable defaultMarker) {
>                         super(defaultMarker);
>                         this.marker = defaultMarker;
>
>                         GeoPoint point = new GeoPoint(
>                                         (int) (myLocation.getLatitude() * 
> 1E6),
>                                         (int) (myLocation.getLongitude() * 
> 1E6));
>                         items.add(new OverlayItem(point, "Me", "My 
> Location"));
>                         populate();
>                 }
>
>                 @Override
>                 protected OverlayItem createItem(int i) {
>                         // TODO Auto-generated method stub
>                         return (OverlayItem) items.get(i);
>                 }
>
>                 public void draw(Canvas canvas, MapView mapView, boolean 
> shadow) {
>                         super.draw(canvas, mapView, shadow);
>
>                         boundCenterBottom(marker);
>                 }
>
>                 @Override
>                 protected boolean onTap(int i) {
>                 Toast.makeText(BrightroidMap.this, "Your Location",
> Toast.LENGTH_SHORT).show();
>
>                 return(true);
>                 }
>
>                 @Override
>                 public int size() {
>                         // TODO Auto-generated method stub
>                         return(items.size());
>                 }
>
>         }
>
>         private class myLocationListener implements LocationListener {
>
>                 @Override
>                 public void onLocationChanged(android.location.Location 
> location) {
>                         // TODO Auto-generated method stub
>                         if (location != null) {
>                                 myLocation = location;
>                                 Toast.makeText(getBaseContext(), "Location 
> changed to " +
> location.getLatitude() + " " + location.getLongitude(),
> Toast.LENGTH_SHORT).show();
>                                 Log.i("Location", location.getLatitude() + ", 
> " +
> location.getLongitude());
>
>                                 GeoPoint point = new GeoPoint(
>                                                 (int) (location.getLatitude() 
> * 1E6),
>                                                 (int) 
> (location.getLongitude() * 1E6));
>                                 controller_Mapview.animateTo(point);
>                                 controller_Mapview.setZoom(16);
>                                 Drawable 
> marker=getResources().getDrawable(R.drawable.icon);
>                                 marker.setBounds(0, 0, 
> marker.getIntrinsicWidth(),
> marker.getIntrinsicHeight());
>                                 view_Mapview.getOverlays().add(new 
> myLocationOverlay(marker));
>                                 view_Mapview.invalidate();
>                                 
> locationManager.removeUpdates(myLocationListener.this);
>                         } else {
>                                 Log.e("Location", "There was no position 
> returned");
>                         }
>                         Log.i("Activity", "We tried to update loaction");
>                 }
>
>                 @Override
>                 public void onProviderDisabled(String provider) {
>                         // TODO Auto-generated method stub
>
>                 }
>
>                 @Override
>                 public void onProviderEnabled(String provider) {
>                         // TODO Auto-generated method stub
>                         Log.i("Provider", provider.toString());
>                 }
>
>                 @Override
>                 public void onStatusChanged(String provider, int status, 
> Bundle
> extras) {
>                         // TODO Auto-generated method stub
>
>                 }
>         }
>
>         public static final int MY_LOCATION = Menu.FIRST;
>         public static final int SUBMIT_LOCATION = Menu.FIRST + 1;
>         public static final int EXIT_ID = Menu.FIRST + 2;
>
>         public Drawable marker;
>
>         private final int GPS_TIMEOUT = 5000;
>
>         private LocationManager locationManager;
>         private LocationListener locationListener;
>         protected Location myLocation = null;
>         private String accessToken;
>
>         private MapView view_Mapview;
>         private MapController controller_Mapview;
>         /** Called when the activity is first created. */
>         @Override
>         public void onCreate(Bundle savedInstanceState) {
>                 super.onCreate(savedInstanceState);
>                 setContentView(R.layout.location);
>
>                 Bundle extras = getIntent().getExtras();
>                 if(extras != null) {
>                         accessToken = (String) 
> extras.getString("accessToken");
>                 }
>                 accessor.accessToken = accessToken;
>                 Log.i("Token", accessor.accessToken);
>
>                 view_Mapview = (MapView) findViewById(R.id.mapview);
>                 controller_Mapview = view_Mapview.getController();
>                 view_Mapview.displayZoomControls(true);
>                 locationManager = (LocationManager)getSystemService
> (Context.LOCATION_SERVICE);
>                 locationManager.getBestProvider(new Criteria(), true);
>         }
>
>         @Override
>                 protected boolean isRouteDisplayed() {
>                 return false;
>         }
>
>         @Override
>     public boolean onCreateOptionsMenu(Menu menu) {
>         boolean result = super.onCreateOptionsMenu(menu);
>         menu.add(0, MY_LOCATION, 0, R.string.my_location);
>         menu.add(0, SUBMIT_LOCATION, 1, R.string.submit_location);
>         menu.add(0, EXIT_ID, 2, R.string.menu_exit);
>         return result;
>     }
>
>         @Override
>     public boolean onOptionsItemSelected(MenuItem item) {
>         switch (item.getItemId()) {
>                 case MY_LOCATION:
>                         locationListener = new myLocationListener();
>                         locationManager.requestLocationUpdates(
>                                         LocationManager.GPS_PROVIDER,
>                                         0,
>                                         0,
>                                         locationListener
>                         );
>
>                         new Handler().postDelayed(new Runnable(){
>                     @Override
>                     public void run() {
>                         locationManager.removeUpdates(locationListener);
>                         Toast.makeText(BrightroidMap.this, "GPS Unable to
> determine location.  Falling back to last known location.",
> Toast.LENGTH_SHORT).show();
>                         myLocation = locationManager.getLastKnownLocation
> ("gps");
>                         GeoPoint point = new GeoPoint(
>                                                         (int) 
> (myLocation.getLatitude() * 1E6),
>                                                         (int) 
> (myLocation.getLongitude() * 1E6));
>                                         controller_Mapview.animateTo(point);
>                                         controller_Mapview.setZoom(16);
>                                         
> marker=getResources().getDrawable(R.drawable.icon);
>                                         marker.setBounds(0, 0, 
> marker.getIntrinsicWidth(),
> marker.getIntrinsicHeight());
>                                         view_Mapview.getOverlays().add(new 
> myLocationOverlay
> (marker));
>                                         view_Mapview.invalidate();
>                     }
>                 }, GPS_TIMEOUT);
>
>                         break;
>                 case SUBMIT_LOCATION:
>
>                         try {
>                                 OAuthMessage result = 
> accessor.newRequestMessage
> (OAuthMessage.GET,
>                                                         
> "http://brightkite.com/places/search.json";,
>                                                         OAuth.newList("q", 
> myLocation.getLatitude() + "," +
> myLocation.getLongitude()));
>                                 Log.i("Request", result.toString());
>                                 try {
>                                 Log.i("Response", 
> result.readBodyAsString().toString());
>                                 } catch (IOException e) {
>                                         Log.e("Error", 
> e.getMessage().toString());
>                                 }
>                                 //JSONObject json_result = new JSONObject(new 
> JSONTokener
> (result.readBodyAsString()));
>
>                                 //Log.i("Location ID", 
> json_result.toString());
>                                 } catch (OAuthException e) {
>                                         // TODO Auto-generated catch block
>                                         Log.e("Error", 
> e.getMessage().toString());
>                                 } catch (IOException e) {
>                                         // TODO Auto-generated catch block
>                                         Log.e("Error", 
> e.getMessage().toString());
>                                 } catch (URISyntaxException e) {
>                                         // TODO Auto-generated catch block
>                                         Log.e("Error", 
> e.getMessage().toString());
>                                 }
>
>                         break;
>                 case EXIT_ID:
>                         finish();
>                         break;
>         }
>         return super.onOptionsItemSelected(item);
>     }
>
> }
>
> On Jan 11, 10:54 pm, Tane Piper <t...@digitalspaghetti.me.uk> wrote:
>
> > 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;
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"OAuth" group.
To post to this group, send email to oauth@googlegroups.com
To unsubscribe from this group, send email to oauth+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/oauth?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to