Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't my call to the Facebook Graph API display anything?
    primarykey
    data
    text
    <p>Ok, so I'm editing this to include the whole class with some new code I added over the past couple of hours. Basically, I'm looking to populate a Google Map with markers that represent a Facebook user's checkins. Unfortunately, my code has not been cooperating - I've tried reviewing the documentation that Facebook provides and searching the web for answers without coming up with anything useful. So far all I've been able to get the app to do is validate the app's permissions with Facebook and display the map, though I had tested the ability to add markers with dummy values in an earlier version of the app and that worked fine.</p> <p>My earlier question dealt with why my calls to the Graph API weren't displaying anything - I had made the same call as listed in the AuthorizeListener sub-class, but was merely attempting to output the raw JSON string in a log entry instead of manipulating it. I think that whatever was the cause of that problem is probably the same cause of my current problem.</p> <p>Anyway, how do I get my app to display markers for locations a user has checked in to? I think my code gets me off to a pretty good start, but there are obviously issues in my AuthorizeListener sub-class. What do you guys think?</p> <pre><code>public class FBCTActivity extends MapActivity { public static Context mContext; List&lt;Overlay&gt; mapOverlays; FBCTMarkerOverlay markerLayer; ArrayList&lt;OverlayItem&gt; overlays = new ArrayList&lt;OverlayItem&gt;(); // Facebook Application ID private static final String APP_ID = ""; Facebook mFacebook = new Facebook(APP_ID); /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; setContentView(R.layout.main); // Set up Facebook stuff mFacebook.authorize(this, new String[]{"user_checkins", "offline_access"}, new AuthorizeListener()); // Set up map stuff MapView mMapView = (MapView)findViewById(R.id.map); mMapView.setSatellite(true); MapController mMapController = mMapView.getController(); mMapController.animateTo(getCurrentLocation()); mMapController.setZoom(3); // Set up overlay stuff mapOverlays = mMapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.icon); markerLayer = new FBCTMarkerOverlay(drawable); // markerLayer is populated in the AuthorizeListener sub-class mapOverlays.add(markerLayer); } /** * Determines the device's current location, but does not display it. * Used for centering the view on the device's location. * @return A GeoPoint object that contains the lat/long coordinates for the device's location. */ private GeoPoint getCurrentLocation() { LocationManager mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Criteria mCriteria = new Criteria(); mCriteria.setAccuracy(Criteria.ACCURACY_COARSE); mCriteria.setPowerRequirement(Criteria.POWER_LOW); String mLocationProvider = mLocationManager.getBestProvider(mCriteria, true); Location mLocation = mLocationManager.getLastKnownLocation(mLocationProvider); int mLat = (int)(mLocation.getLatitude()*1E6); int mLong = (int)(mLocation.getLongitude()*1E6); return new GeoPoint(mLat, mLong); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } private class AuthorizeListener implements DialogListener { public void onComplete(Bundle values) { new Thread() { @Override public void run() { try { String response = mFacebook.request("me/checkins"); // The JSON to get JSONObject jObject = Util.parseJson(response); JSONArray jArray = jObject.getJSONArray("data"); // Read the JSON array returned by the request for (int i = 0; i &lt; jArray.length(); i++) { // Iterate through the array JSONObject outerPlace = jArray.getJSONObject(i); // The outer JSON object JSONObject place = outerPlace.getJSONObject("place"); // Second-tier JSON object that contains id, name, and location values for the "place" String placeName = place.getString("name"); // The place's name JSONObject placeLocation = place.getJSONObject("location"); // Third-tier JSON object that contains latitude and longitude coordinates for the place's "location" int lat = (int) (placeLocation.getDouble("latitude")*1E6); // The place's latitude int lon = (int) (placeLocation.getDouble("longitude")*1E6); // The place's longitude String date = outerPlace.getString("created_time"); // Timestamp of the checkin overlays.add(new OverlayItem(new GeoPoint(lat, lon), placeName, "Checked in on: " + date)); // Add the place's details to our ArrayList of OverlayItems } mFacebook.logout(mContext); // Logout of Facebook for (int i = 0; i &lt; overlays.size(); i++) { markerLayer.addOverlayItem(overlays.get(i)); } } catch(IOException e) { Log.v("FBCTActivity", e.getMessage()); } catch(JSONException e) { Log.v("FBCTActivity", e.getMessage()); } } }.start(); } public void onFacebookError(FacebookError e) { Log.w("FBCTActivity", e.getMessage()); // TODO: Add more graceful error handling } public void onError(DialogError e) { Log.w("FBCTActivity", e.getMessage()); } public void onCancel() { // TODO Auto-generated method stub } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload