我想获取我朋友列表中的所有生日.我已经尝试了好几天.我的代码如下.
Facebook facebook = new Facebook(<MY_FACEBOOK_ID>);@OverrIDepublic voID onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); mContext = this; setContentVIEw(R.layout.main); showNotification(); final String[] PERMISSIONS = new String[] {"user_location", "user_birthday"}; facebook.authorize(this, PERMISSIONS, new DialogListener() { @OverrIDe public voID onComplete(Bundle values) {} @OverrIDe public voID onCancel() {} @OverrIDe public voID onFacebookError(FacebookError e) { // Todo auto-generated method stub } @OverrIDe public voID one rror(DialogError e) { // Todo auto-generated method stub } }); try { String token = facebook.getAccesstoken(); Bundle bundle = new Bundle(); bundle.putString("fIElds", "ID,name"); bundle.putString("access_token", token); String response = facebook.request( "me/frIEnds", bundle ); facebook.setAccesstoken(facebook.getAccesstoken()); Toast.makeText(mContext, token , Toast.LENGTH_LONG).show(); Toast.makeText(mContext, response, Toast.LENGTH_LONG).show(); JsONObject Json = Util.parseJson( response ); JsONArray data = Json.getJsONArray( "data" ); for ( int i = 0; i < data.length(); i++ ) { JsONObject frIEnd = data.getJsONObject( i ); String ID = frIEnd.getString( "ID" ); String name = frIEnd.getString( "name" ); Toast.makeText(mContext, "ID: "+ ID , Toast.LENGTH_LONG).show(); Toast.makeText(mContext, "name: "+ name , Toast.LENGTH_LONG).show(); }
每次我使用此代码都会产生错误.并且令牌都显示为空,响应都显示为问题
“必须使用活动访问令牌来查询有关当前用户的信息”
解决方法:
创建一个方法:
getProfileinformation()
在方法主体中,您必须编写:
public voID getProfileinformation() {mAsyncRunner.request("me", new RequestListener() { @OverrIDe public voID onComplete(String response, Object state) { Log.d("Profile", response); String Json = response; try { JsONObject profile = new JsONObject(Json); // getting name of the user String name = profile.getString("name"); // getting email of the user String email = profile.getString("email"); //getting user birthday String birth_day=profile.getString("birthday"); runOnUiThread(new Runnable() { @OverrIDe public voID run() { Toast.makeText(getApplicationContext(), "name: " + name + "\nEmail: " + email, Toast.LENGTH_LONG).show(); } }); } catch (JsONException e) { e.printstacktrace(); } } @OverrIDe public voID onIOException(IOException e, Object state) { } @OverrIDe public voID onfileNotFoundException(fileNotFoundException e, Object state) { } @OverrIDe public voID onMalformedURLException(MalformedURLException e, Object state) { } @OverrIDe public voID onFacebookError(FacebookError e, Object state) { }});
}
上面的函数将从facebook获取Json数据.您需要解析Json以获得单独的配置文件数据.
来自Facebook的示例配置文件Json将如下所示:
{ "ID": "1464730016", "name": "XYZ", "first_name": "XYZ", "last_name": "ABC", "link": "https://....", "username": "XYZ", "birthday": "22/10/89", "hometown": }
有关更多详细信息,请参阅:
http://www.androIDhive.info/2012/03/android-facebook-connect-tutorial/
总结 以上是内存溢出为你收集整理的Java-Android从Facebook个人资料获取生日日期全部内容,希望文章能够帮你解决Java-Android从Facebook个人资料获取生日日期所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)