获取Facebook好友列表当月的生日

时间:2013-01-12 04:18:05

标签: android facebook facebook-graph-api

我正在编写一个应用程序,其中使用名称,DOB和个人资料图片 获取我所有Facebook好友的列表

所以我的问题是如何在当月获取那些生日的朋友列表..只有当月朋友生日列表 ....

代码:

 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));
}

2 个答案:

答案 0 :(得分:0)

更改您当前的查询:

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

对此:

String revisedQuery = "SELECT uid, name, pic_square, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) AND birthday_date >= '01/01' AND birthday_date <= '01/31' ORDER BY birthday_date ASC";

String revisedQuerybirthday_date >= '01/01'birthday_date <= '01/31'中的参数是您在特定月份内需要更改以获取出生日期的参数。

答案 1 :(得分:0)

更新:

使用thais查询: -

"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));
}