2011-01-24 12 views
0

これで、過去2〜3時間かけて追加した新しいコードをクラス全体に含めるように編集しています。基本的には、GoogleマップにFacebookのユーザーのチェックインを表すマーカーを挿入することを検討しています。残念ながら、私のコードは協力していません - 私はFacebookが提供しているドキュメンテーションを見直してみました。これまでのところ、アプリを入手できるようになったのは、Facebookのアプリの権限を検証して地図を表示することです。ただし、以前のバージョンのダミー値をマーカーに追加する機能をテストしたところうまくいきました。Facebook Graph APIの呼び出しで何も表示されないのはなぜですか?

私の以前の質問では、Graph APIへの呼び出しで何も表示されなかった理由がわかりました。私はAuthorizeListenerサブクラスにリストされているものと同じ呼び出しを行いましたが、エントリを操作するのではなく、私はその問題の原因が何であっても、おそらく私の現在の問題と同じ原因だと思います。

とにかく、ユーザーがチェックインした場所のマーカーを表示するにはどうすればよいですか?私のコードはかなり良いスタートを切ってくれますが、私のAuthorizeListenerサブクラスには明らかに問題があります。皆さんはどう思いますか?

public class FBCTActivity extends MapActivity { 
public static Context mContext; 
List<Overlay> mapOverlays; 
FBCTMarkerOverlay markerLayer; 
ArrayList<OverlayItem> overlays = new ArrayList<OverlayItem>(); 

// 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 < 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 < 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 

    } 
} 

}

+0

あなたは認証されていますか? – Bozho

+0

私は正しく認証されていると信じています。私はFacebook SDKを使用することについては、ノブであるので、私は完全にオフベースになる可能性があります - 私がどのように認証しているかを見るために私の編集されたポストを見てください。 – Todd

答えて

0

それが理由ではないかもしれませんが、アプリのIDを定義していない:

private static final String APP_ID = ""; 

また、あなたが呼び出す活動にonActivityResultをオーバーライドする必要がmFacebook.authorizeは、ので、あなたのコードにこれを追加します。そうしない場合は

@Override 
protected void onActivityResult(int requestCode, int resultCode, 
           Intent data) { 
    mFacebook.authorizeCallback(requestCode, resultCode, data); 
} 

すると、アプリケーションが取得することはありませんグラフのトークンと接続がJSONエラーメッセージを返します。

関連する問題