本文介绍了取Facebook的好友列表当月的生日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在我的应用程序的我所有的Facebook好友列表获取的与他们的姓名,出生日期和个人资料照片

所以在这里我的问题是我怎么能获取的好友列表当月的生日..唯一的当月朋友的生日列表 ...

code:

 公共类FriendListAdapter扩展BaseAdapter实现SectionIndexer
{
    私人LayoutInflater mInflater;
    私人GetProfilePictures picturesGatherer = NULL;
    FriendsList friendsList;
    私有String []段;    哈希表<整数,FriendItem> listofshit = NULL;    公共FriendListAdapter(FriendsList friendsList)
    {
        this.friendsList = friendsList;
        部分=新的String [getCount将()];
        listofshit =新的Hashtable<整数,FriendItem>();
        的for(int i = 0; I< getCount将();我++)
        {
         尝试
            {
                。区段[I] = jsonArray.getJSONObject(ⅰ).getString(名称)串(0);
                。部分[I] = jsonArray.getJSONObject(I).getString(生日),子(1);
            }
         赶上(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_TAGgetItemId());
        返回的位置;
    }    公共查看getView(INT位置,查看convertView,父母的ViewGroup)
    {
        Log.d(LOG_TAGgetView(+位置+));        的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(){
        返回段;
    }
}

=============================================== ===================================

 公共静态无效requestFriends(FacebookRequest facebookRequest){
    Log.d(LOG_TAGrequestFriends(+));
    查询字符串=选择姓名,生日,UID,从用户那里pic_square
      在的uid(从朋友选择UID2哪里UID1 =我())由birthday_date秩序;
    捆绑PARAMS =新包();
    params.putString(法,fql.query);
    params.putString(查询,查询);
    FacebookUtility.asyncRunner.request(NULL,则params,
    新FacebookRequestListener(FacebookRequestListener.FRIENDS,facebookRequest));
}


解决方案

更新:

使用泰国查询: -

 选择姓名,生日,UID,从用户pic_square其中uid中(从朋友选择UID2哪里UID1 =我())和月(生日)= MONTH(GETDATE())为了通过birthday_date 公共静态无效requestFriends(FacebookRequest facebookRequest){
    Log.d(LOG_TAGrequestFriends(+));
    查询字符串=选择姓名,生日,UID,pic_square从用户其中uid中(从朋友选择UID2哪里UID1 =我())和月(生日)=本月birthday_date(GETDATE())令;
    捆绑PARAMS =新包();
    params.putString(法,fql.query);
    params.putString(查询,查询);
    FacebookUtility.asyncRunner.request(NULL,则params,
    新FacebookRequestListener(FacebookRequestListener.FRIENDS,facebookRequest));
}

I am writing an app in which I am fetching list of all my Facebook friends with their Name, DOB and Profile Picture.

So here my question is how can i fetch list of friends those birthdays in current month.. only list of current month friends birthdays....

Code:

 public class FriendListAdapter extends BaseAdapter implements SectionIndexer 
{
    private LayoutInflater mInflater;   
    private GetProfilePictures picturesGatherer = null;
    FriendsList friendsList;
    private String[] sections;

    Hashtable<Integer, FriendItem> listofshit = null;

    public FriendListAdapter(FriendsList friendsList) 
    {
        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);
                sections[i] = jsonArray.getJSONObject(i).getString("birthday").substring(1);
            }
         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;
    }
}

==================================================================================

    public static void requestFriends(FacebookRequest facebookRequest) {
    Log.d(LOG_TAG, "requestFriends(" + ")");
    String query = "select name, birthday, uid, pic_square from user where 
      uid in (select uid2 from friend where uid1=me()) order by birthday_date";
    Bundle params = new Bundle();
    params.putString("method", "fql.query");
    params.putString("query", query);
    FacebookUtility.asyncRunner.request(null, params, 
    new FacebookRequestListener(FacebookRequestListener.FRIENDS, facebookRequest));
}
解决方案

UPDATED :

Use thais query :-

"select name, birthday, uid, pic_square from user where uid in (select uid2 from friend where uid1=me()) AND MONTH(birthday) = MONTH(GETDATE()) order by birthday_date";

 public static void requestFriends(FacebookRequest facebookRequest) {
    Log.d(LOG_TAG, "requestFriends(" + ")");
    String query = "select name, birthday, uid, pic_square from user where uid in (select uid2 from friend where uid1=me()) AND MONTH(birthday) = MONTH(GETDATE()) order by birthday_date";
    Bundle params = new Bundle();
    params.putString("method", "fql.query");
    params.putString("query", query);
    FacebookUtility.asyncRunner.request(null, params, 
    new FacebookRequestListener(FacebookRequestListener.FRIENDS, facebookRequest));
}

这篇关于取Facebook的好友列表当月的生日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 16:23