如何获得FB朋友生日的Android [英] How to get FB friends birthday in Android
本文介绍了如何获得FB朋友生日的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这样code https://github.com/chrtatu/FacebookFriendsList 得到的FB朋友,他们的名字和个人资料图片列表。
在这里,我试图让自己的出生日期为好,但在地方DOB的,我得到的空值。
请大家帮忙去取了。
我的code:
的String [] facebook_permissions = {user_photos,friends_birthday,friends_photos};
================================================== ========================
公共类FriendListAdapter扩展了BaseAdapter实现SectionIndexer {
私人LayoutInflater mInflater;
私有String []段;
私人GetProfilePictures picturesGatherer = NULL;
FriendsList friendsList;
哈希表<整数,FriendItem> listofshit = NULL;
公共FriendListAdapter(FriendsList friendsList){
Log.d(LOG_TAG,FriendListAdapter());
this.friendsList = friendsList;
部分=新的String [getCount将()];
listofshit =新的Hashtable<整数,FriendItem>();
的for(int i = 0; I< getCount将();我++){
尝试 {
区段[I] = jsonArray.getJSONObject(ⅰ).getString(姓名)子(0,1)。
区段[I] = jsonArray.getJSONObject(ⅰ).getString(生日)子串(0,2)。
}赶上(JSONException E){
区段[I] =;
Log.e(LOG_TAGgetJSONObject:+ e.getMessage());
}
}
如果(picturesGatherer == NULL){
picturesGatherer =新GetProfilePictures();
}
picturesGatherer.setAdapterForListener(本);
mInflater = LayoutInflater.from(friendsList.getBaseContext());
}
公众诠释getCount将(){
Log.d(LOG_TAG,getCount将());
如果(jsonArray == NULL)
返回0;
返回jsonArray.length();
}
公共对象的getItem(INT位置){
Log.d(LOG_TAG的getItem());
返回listofshit.get(位置);
}
众长getItemId(INT位置){
Log.d(LOG_TAG,getItemId());
返回的位置;
}
公共查看getView(INT位置,查看convertView,ViewGroup中父){
Log.d(LOG_TAG,getView(+位置+));
的JSONObject的JSONObject = NULL;
尝试 {
的JSONObject = jsonArray.getJSONObject(位置);
}赶上(JSONException E){
Log.e(LOG_TAGgetJSONObject:+ e.getMessage());
}
FriendItem friendItem;
如果(convertView == NULL){
convertView = mInflater.inflate(R.layout.single_friend,NULL);
friendItem =新FriendItem();
convertView.setTag(friendItem);
}
其他 {
friendItem =(FriendItem)convertView.getTag();
}
friendItem.friendPicture =(ImageView的)convertView.findViewById(R.id.picture_square);
friendItem.friendName =(TextView中)convertView.findViewById(R.id.name);
friendItem.friendDob =(TextView中)convertView.findViewById(R.id.dob);
friendItem.friendLayout =(RelativeLayout的)convertView.findViewById(R.id.friend_item);
尝试 {
字符串的uid = jsonObject.getString(UID);
字符串URL = jsonObject.getString(pic_square);
friendItem.friendPicture.setImageBitmap(picturesGatherer.getPicture(UID,URL));
}赶上(JSONException E){
Log.e(LOG_TAGgetJSONObject:+ e.getMessage());
friendItem.friendName.setText();
friendItem.friendDob.setText();
}
尝试 {
friendItem.friendName.setText(jsonObject.getString(名字));
friendItem.friendDob.setText(jsonObject.getString(生日));
}赶上(JSONException E){
Log.e(LOG_TAGgetJSONObject:+ e.getMessage());
friendItem.friendName.setText();
friendItem.friendDob.setText();
}
listofshit.put(位置,friendItem);
返回convertView;
}
公众诠释getPositionForSection(INT位置){
返回的位置;
}
公众诠释getSectionForPosition(INT位置){
返回的位置;
}
公共对象[] getSections(){
返回段;
}
}
类FriendItem {
TextView的friendDob;
INT ID;
ImageView的friendPicture;
TextView的friendName;
RelativeLayout的friendLayout;
}
================================================== ============================
字符串查询=选择名称,UID,pic_square,生日从用户那里UID在
(请从朋友那里UID2 UID1 =我())命令的名字;
解决方案
相反,这两条线路的code的:
部分[I] = jsonArray.getJSONObject(我).getString(姓名)子(0,1)。
区段[I] = jsonArray.getJSONObject(ⅰ).getString(生日)子串(0,2)。
使用下面两行:
部分[I] = jsonArray.getJSONObject(我).getString(name)的子串(0);
。区段[I] = jsonArray.getJSONObject(ⅰ).getString(生日)子(1);
I am using this sample code https://github.com/chrtatu/FacebookFriendsList to get the list of FB friends with their names and profile pics.
Here I try to get their DOB as well, but in place of DOB, I get null value.
please help to fetch that.
My Code:
String[] facebook_permissions = { "user_photos", "friends_birthday", "friends_photos" };
==========================================================================
public class FriendListAdapter extends BaseAdapter implements SectionIndexer {
private LayoutInflater mInflater;
private String[] sections;
private GetProfilePictures picturesGatherer = null;
FriendsList friendsList;
Hashtable<Integer, FriendItem> listofshit = null;
public FriendListAdapter(FriendsList friendsList) {
Log.d(LOG_TAG, "FriendListAdapter()");
this.friendsList = friendsList;
sections = new String[getCount()];
listofshit = new Hashtable<Integer, FriendItem>();
for (int i = 0; i < getCount(); i++) {
try {
sections[i] = jsonArray.getJSONObject(i).getString("name").substring(0, 1);
sections[i] = jsonArray.getJSONObject(i).getString("birthday").substring(0, 2);
} catch (JSONException e) {
sections[i] = "";
Log.e(LOG_TAG, "getJSONObject: " + e.getMessage());
}
}
if (picturesGatherer == null) {
picturesGatherer = new GetProfilePictures();
}
picturesGatherer.setAdapterForListener(this);
mInflater = LayoutInflater.from(friendsList.getBaseContext());
}
public int getCount() {
Log.d(LOG_TAG, "getCount()");
if (jsonArray == null)
return 0;
return jsonArray.length();
}
public Object getItem(int position) {
Log.d(LOG_TAG, "getItem()");
return listofshit.get(position);
}
public long getItemId(int position) {
Log.d(LOG_TAG, "getItemId()");
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
Log.d(LOG_TAG, "getView(" + position + ")");
JSONObject jsonObject = null;
try {
jsonObject = jsonArray.getJSONObject(position);
} catch (JSONException e) {
Log.e(LOG_TAG, "getJSONObject: " + e.getMessage());
}
FriendItem friendItem;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.single_friend, null);
friendItem = new FriendItem();
convertView.setTag(friendItem);
}
else {
friendItem = (FriendItem) convertView.getTag();
}
friendItem.friendPicture = (ImageView) convertView.findViewById(R.id.picture_square);
friendItem.friendName = (TextView) convertView.findViewById(R.id.name);
friendItem.friendDob = (TextView) convertView.findViewById(R.id.dob);
friendItem.friendLayout = (RelativeLayout) convertView.findViewById(R.id.friend_item);
try {
String uid = jsonObject.getString("uid");
String url = jsonObject.getString("pic_square");
friendItem.friendPicture.setImageBitmap(picturesGatherer.getPicture(uid, url));
} catch (JSONException e) {
Log.e(LOG_TAG, "getJSONObject: " + e.getMessage());
friendItem.friendName.setText("");
friendItem.friendDob.setText("");
}
try {
friendItem.friendName.setText(jsonObject.getString("name"));
friendItem.friendDob.setText(jsonObject.getString("birthday"));
} catch (JSONException e) {
Log.e(LOG_TAG, "getJSONObject: " + e.getMessage());
friendItem.friendName.setText("");
friendItem.friendDob.setText("");
}
listofshit.put(position, friendItem);
return convertView;
}
public int getPositionForSection(int position) {
return position;
}
public int getSectionForPosition(int position) {
return position;
}
public Object[] getSections() {
return sections;
}
}
class FriendItem {
TextView friendDob;
int id;
ImageView friendPicture;
TextView friendName;
RelativeLayout friendLayout;
}
==============================================================================
String query = "select name, uid, pic_square, birthday from user where uid in
(select uid2 from friend where uid1=me()) order by name";
解决方案
Instead of these two lines of code:
sections[i] = jsonArray.getJSONObject(i).getString("name").substring(0, 1);
sections[i] = jsonArray.getJSONObject(i).getString("birthday").substring(0, 2);
Use below two lines:
sections[i] = jsonArray.getJSONObject(i).getString("name").substring(0);
sections[i] = jsonArray.getJSONObject(i).getString("birthday").substring(1);
这篇关于如何获得FB朋友生日的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文