Java 为什么';我对Facebook Graph API的调用没有显示任何内容吗?
好的,我正在编辑这个,用我在过去几个小时里添加的一些新代码来包含整个类。基本上,我想用表示Facebook用户签入的标记填充Google地图。不幸的是,我的代码一直不配合——我试图查看Facebook提供的文档,并在网上搜索答案,但没有找到任何有用的东西。到目前为止,我所能做的只是通过Facebook验证应用程序的权限并显示地图,尽管我已经测试了在早期版本的应用程序中添加带有虚拟值的标记的能力,效果很好 我之前的问题涉及为什么我对Graph API的调用没有显示任何内容——我进行了与AuthorizeListener子类中列出的相同的调用,但只是尝试在日志条目中输出原始JSON字符串,而不是对其进行操作。我认为无论是什么原因导致了这个问题,都可能是我目前问题的原因 无论如何,如何让我的应用程序显示用户已签入位置的标记?我认为我的代码让我有了一个很好的开始,但是我的AuthorizeListener子类中显然存在一些问题。你们觉得怎么样Java 为什么';我对Facebook Graph API的调用没有显示任何内容吗?,java,android,facebook-graph-api,facebook-android-sdk,Java,Android,Facebook Graph Api,Facebook Android Sdk,好的,我正在编辑这个,用我在过去几个小时里添加的一些新代码来包含整个类。基本上,我想用表示Facebook用户签入的标记填充Google地图。不幸的是,我的代码一直不配合——我试图查看Facebook提供的文档,并在网上搜索答案,但没有找到任何有用的东西。到目前为止,我所能做的只是通过Facebook验证应用程序的权限并显示地图,尽管我已经测试了在早期版本的应用程序中添加带有虚拟值的标记的能力,效果很好 我之前的问题涉及为什么我对Graph API的调用没有显示任何内容——我进行了与Author
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
}
}
公共类FBCTActivity扩展了MapActivity{
公共静态语境;
列出地图覆盖图;
FBCTMarkerOverlay markerLayer;
ArrayList覆盖=新建ArrayList();
//Facebook应用程序ID
私有静态最终字符串APP_ID=“”;
Facebook mFacebook=新Facebook(应用程序ID);
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mContext=这个;
setContentView(R.layout.main);
//建立Facebook的东西
authorize(这个,新字符串[]{“user_checkins”,“offline_access”},新的AuthorizeListener());
//设置地图资料
MapView mMapView=(MapView)findViewById(R.id.map);
mMapView.setSatellite(真);
MapController mMapController=mMapView.getController();
mMapController.animateTo(getCurrentLocation());
mMapController.setZoom(3);
//设置覆盖内容
mapOverlays=mMapView.getOverlays();
Drawable Drawable=this.getResources().getDrawable(R.Drawable.icon);
markerLayer=新FBCTMarkerOverlay(可拉伸);
//markerLayer在AuthorizeListener子类中填充
mapOverlays.add(markerLayer);
}
/**
*确定设备的当前位置,但不显示它。
*用于将视图置于设备位置的中心。
*@返回一个包含设备位置横向/纵向坐标的地质点对象。
*/
专用地质点getCurrentLocation(){
LocationManager MLLocationManager=(LocationManager)getSystemService(Context.LOCATION\u服务);
标准mCriteria=新标准();
mCriteria.setaccurity(标准:精度_粗略);
mCriteria.setPowerRequirement(标准功率低);
字符串mLocationProvider=mLocationManager.getBestProvider(mCriteria,true);
Location mLocation=mLocationManager.getLastKnownLocation(mLocationProvider);
int mLat=(int)(mLocation.getLatitude()*1E6);
int mLong=(int)(mLocation.getLongitude()*1E6);
返回新的地质点(mLat、mLong);
}
@凌驾
受保护的布尔值isRouteDisplayed(){
//TODO自动生成的方法存根
返回false;
}
私有类AuthorizeListener实现DialogListener{
未完成的公共void(捆绑值){
新线程(){
@凌驾
公开募捐{
试一试{
String response=mFacebook.request(“me/checkins”);//要获取的JSON
JSONObject jObject=Util.parseJson(响应);
JSONArray jArray=jObject.getJSONArray(“数据”);//读取请求返回的JSON数组
对于(int i=0;i
}这可能不是原因,但您尚未定义应用程序ID:
private static final String APP_ID = "";
而且,你必须
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
mFacebook.authorizeCallback(requestCode, resultCode, data);
}