我正在用fb api做一些测试。我在两个不同的帐户中执行两个查询。查询是:
SELECT name,friend_count FROM user WHERE uid = me()
和
选择uid,来自uid in的用户的名字(从朋友那里选择uid1) UID2 =我())
在我的程序(我在下面列出)中,每个执行的查询都显示返回的行数。在其中一个帐户中,friend_count的值为637,在第二个查询中返回599行。我认为这个结果是正确的,因为某些帐户可能已停用。但是,在另一个帐户中,friend_count的值为3599,但仅返回4行是第二个帐户。我不明白为什么会这样。我是权限,但似乎两个帐户中的一切都是相同的。
下面,我列出了我的代码。每次我想用其他帐户执行时,我都会更改第44行。这一行是auth = vectAuth [0];或者auth = vectAuth [1];我正在使用facebook4j api。
编辑: 我使用Graph API(me /?fields = friends)进行了更多测试,我发现对于拥有637位朋友的帐户,我使用api V1.0获得599位朋友,使用api V2.0获得3位朋友。在第二个帐户中,我在两个版本的API中获得了4个朋友。
包facebookapitest;
import facebook4j.Facebook; import facebook4j.FacebookException; import facebook4j.FacebookFactory; import facebook4j.conf.ConfigurationBuilder; import facebook4j.internal.org.json.JSONArray; import facebook4j.internal.org.json.JSONException; import facebook4j.internal.org.json.JSONObject; import java.util.Iterator; import static genericClasses.genericClasses.newline; /** * * @author mba */ public class FacebookAPITest { private static final String commaSeparetedPermissions = "ads_management, ads_read, create_event, create_note, email, export_stream, friends_about_me, friends_actions.books, friends_actions.music, friends_actions.news, friends_actions.video, friends_activities, friends_birthday, friends_education_history, friends_events, friends_games_activity, friends_groups, friends_hometown, friends_interests, friends_likes, friends_location, friends_notes, friends_online_presence, friends_photo_video_tags, friends_photos, friends_questions, friends_relationship_details, friends_relationships, friends_religion_politics, friends_status, friends_subscriptions, friends_videos, friends_website, friends_work_history, manage_friendlists, manage_notifications, manage_pages, photo_upload, publish_actions, publish_stream, read_friendlists, read_insights, read_mailbox, read_page_mailboxes, read_requests, read_stream, rsvp_event, share_item, sms, status_update, user_about_me, user_actions.books, user_actions.music, user_actions.news, user_actions.video, user_activities, user_birthday, user_education_history, user_events, user_friends, user_games_activity, user_groups, user_hometown, user_interests, user_likes, user_location, user_notes, user_online_presence, user_photo_video_tags, user_photos, user_questions, user_relationship_details, user_relationships, user_religion_politics, user_status, user_subscriptions, user_videos, user_website, user_work_history, video_upload, xmpp_login"; private static final Auth[] vectAuth = new Auth [] { new Auth("***AppID***", "***appSecret***", commaSeparetedPermissions, "***userToken***"), new Auth("***AppID***", "***appSecret***", commaSeparetedPermissions, "***userToken***"), }; static Auth auth; /** * @param args the command line arguments */ public static void main(String[] args) throws JSONException, FacebookException { auth = vectAuth[0]; Facebook facebook = createConn(); String query; System.out.println("Query 1"); query = "SELECT name, friend_count FROM user WHERE uid=me()"; testFQL(facebook, query); System.out.println("Query 2"); query = "select uid, name from user where uid in (select uid1 from friend where uid2=me())"; testFQL(facebook, query); } private static Facebook createConn() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true) .setOAuthAppId(auth.getappId()) .setOAuthAppSecret(auth.getappSecret()) .setOAuthAccessToken(auth.getaccessToken()) .setOAuthPermissions(auth.getcommaSeparetedPermissions()); FacebookFactory ff = new FacebookFactory(cb.build()); Facebook facebook = ff.getInstance(); return facebook; } private static void testFQL(Facebook facebook, String query) throws FacebookException, JSONException { JSONArray jsonArray = execFQL(facebook, query); printFQLJSON(jsonArray); } private static JSONArray execFQL(Facebook facebook, String query) throws FacebookException { return facebook.fql().executeFQL(query); } private static void printFQLJSON (JSONArray jsonArray) throws JSONException { String result = ""; for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); String row = getRow(jsonObject); result += row + newline; } System.out.println(result); System.out.println(""+jsonArray.length() + " records listed"); } private static String getRow(JSONObject jsonObject) throws JSONException { Iterator it = jsonObject.keys(); String row = ""; while(it.hasNext()) { String key = (String) it.next(); row += key + " -> " + jsonObject.get(key) + ";"; } return row; } }
public class Auth { private String appId; private String appSecret; private String commaSeparetedPermissions; private String accessToken;
public Auth(String p_appId, String p_appSecret, String p_commaSeparetedPermissions, String p_accessToken) { appId = p_appId; appSecret = p_appSecret; commaSeparetedPermissions = p_commaSeparetedPermissions; accessToken = p_accessToken; } public String getappId() { return appId; } public String getappSecret() { return appSecret; } public String getcommaSeparetedPermissions() { return commaSeparetedPermissions; } public String getaccessToken() { return accessToken; }
}