⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 facebookrestclient.java

📁 FACEBOOK上
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
  /**   * Used to retrieve photo objects using the search parameters (one or more of the   * parameters must be provided).   *   * @param subjId retrieve from photos associated with this user (optional).   * @return an T of photo objects.   * @see #photos_get(Integer, Long, Collection)   * @see <a href="http://wiki.developers.facebook.com/index.php/Photos.get">   *      Developers Wiki: Photos.get</a>   */  public T photos_get(Integer subjId)    throws FacebookException, IOException {    return photos_get(subjId, /*albumId*/null, /*photoIds*/null);  }  /**   * Used to retrieve photo objects using the search parameters (one or more of the   * parameters must be provided).   *   * @param albumId retrieve from photos from this album (optional)   * @return an T of photo objects.   * @see #photos_get(Integer, Long, Collection)   * @see <a href="http://wiki.developers.facebook.com/index.php/Photos.get">   *      Developers Wiki: Photos.get</a>   */  public T photos_get(Long albumId)    throws FacebookException, IOException {    return photos_get(/*subjId*/null, albumId, /*photoIds*/null);  }  /**   * Used to retrieve photo objects using the search parameters (one or more of the   * parameters must be provided).   *   * @param subjId retrieve from photos associated with this user (optional).   * @param albumId retrieve from photos from this album (optional)   * @param photoIds retrieve from this list of photos (optional)   * @return an T of photo objects.   * @see <a href="http://wiki.developers.facebook.com/index.php/Photos.get">   *      Developers Wiki: Photos.get</a>   */  public T photos_get(Integer subjId, Long albumId, Collection<Long> photoIds)    throws FacebookException, IOException {    ArrayList<Pair<String, CharSequence>> params =      new ArrayList<Pair<String, CharSequence>>(FacebookMethod.PHOTOS_GET.numParams());    boolean hasUserId = null != subjId && 0 != subjId;    boolean hasAlbumId = null != albumId && 0 != albumId;    boolean hasPhotoIds = null != photoIds && !photoIds.isEmpty();    if (!hasUserId && !hasAlbumId && !hasPhotoIds) {      throw new IllegalArgumentException("At least one of photoIds, albumId, or subjId must be provided");    }    if (hasUserId)      params.add(new Pair<String, CharSequence>("subj_id", Integer.toString(subjId)));    if (hasAlbumId)      params.add(new Pair<String, CharSequence>("aid", Long.toString(albumId)));    if (hasPhotoIds)      params.add(new Pair<String, CharSequence>("pids", delimit(photoIds)));    return this.callMethod(FacebookMethod.PHOTOS_GET, params);  }  /**   * Retrieves the requested info fields for the requested set of users.   * @param userIds a collection of user IDs for which to fetch info   * @param fields a set of strings describing the info fields desired, such as "last_name", "sex"   * @return a T consisting of a list of users, with each user element   * containing the requested fields.   */  public T users_getInfo(Collection<Integer> userIds, Set<CharSequence> fields)    throws FacebookException, IOException {    // assertions test for invalid params    if (null == userIds) {      throw new IllegalArgumentException("userIds cannot be null");    }    if (fields == null || fields.isEmpty()) {      throw new IllegalArgumentException("fields should not be empty");    }    return this.callMethod(FacebookMethod.USERS_GET_INFO,                           new Pair<String, CharSequence>("uids", delimit(userIds)),                           new Pair<String, CharSequence>("fields", delimit(fields)));  }  /**   * Retrieves the tags for the given set of photos.   * @param photoIds The list of photos from which to extract photo tags.   * @return the created album   */  public T photos_getTags(Collection<Long> photoIds)    throws FacebookException, IOException {    return this.callMethod(FacebookMethod.PHOTOS_GET_TAGS,                           new Pair<String, CharSequence>("pids", delimit(photoIds)));  }  /**   * Retrieves the groups associated with a user   * @param userId Optional: User associated with groups.   * A null parameter will default to the session user.   * @param groupIds Optional: group ids to query.   * A null parameter will get all groups for the user.   * @return array of groups   */  public T groups_get(Integer userId, Collection<Long> groupIds)    throws FacebookException, IOException {    boolean hasGroups = (null != groupIds && !groupIds.isEmpty());    if (null != userId)      return hasGroups ?             this.callMethod(FacebookMethod.GROUPS_GET, new Pair<String, CharSequence>("uid", userId.toString()),                             new Pair<String, CharSequence>("gids", delimit(groupIds))) :             this.callMethod(FacebookMethod.GROUPS_GET, new Pair<String, CharSequence>("uid", userId.toString()));    else      return hasGroups ?             this.callMethod(FacebookMethod.GROUPS_GET, new Pair<String, CharSequence>("gids", delimit(groupIds))) :             this.callMethod(FacebookMethod.GROUPS_GET);  }  /**   * Call the specified method, with the given parameters, and return a DOM tree with the results.   *   * @param method the fieldName of the method   * @param paramPairs a list of arguments to the method   * @throws Exception with a description of any errors given to us by the server.   */  protected T callMethod(IFacebookMethod method, Collection<Pair<String, CharSequence>> paramPairs)    throws FacebookException, IOException {    HashMap<String, CharSequence> params =      new HashMap<String, CharSequence>(2 * method.numTotalParams());    params.put("method", method.methodName());    params.put("api_key", _apiKey);    params.put("v", TARGET_API_VERSION);    String format = getResponseFormat();    if (null != format) {      params.put("format", format);    }    if (method.requiresSession()) {      params.put("call_id", Long.toString(System.currentTimeMillis()));      params.put("session_key", _sessionKey);    }    CharSequence oldVal;    for (Pair<String, CharSequence> p : paramPairs) {      oldVal = params.put(p.first, p.second);      if (oldVal != null)        System.err.printf("For parameter %s, overwrote old value %s with new value %s.", p.first,                          oldVal, p.second);    }    assert (!params.containsKey("sig"));    String signature =      generateSignature(FacebookSignatureUtil.convert(params.entrySet()), method.requiresSession());    params.put("sig", signature);    boolean doHttps = this.isDesktop() && FacebookMethod.AUTH_GET_SESSION.equals(method);    InputStream data =      method.takesFile() ? postFileRequest(method.methodName(), params) : postRequest(method.methodName(),                                                                                      params,                                                                                      doHttps,                                                                                      true);    return parseCallResult(data, method);  }  /**   * Parses the result of an API call into a T.   * @param data an InputStream with the results of a request to the Facebook servers   * @param method the method called   * @throws FacebookException if <code>data</code> represents an error   * @throws IOException if <code>data</code> is not readable   * @return a T   */  protected abstract T parseCallResult(InputStream data, IFacebookMethod method)    throws FacebookException, IOException;  /**   * Recaches the referenced url.   * @param url the URL to refresh   * @return boolean indicating whether the refresh succeeded   */  public boolean fbml_refreshRefUrl(URL url)    throws FacebookException, IOException {    return extractBoolean(this.callMethod(FacebookMethod.FBML_REFRESH_REF_URL,                                          new Pair<String, CharSequence>("url", url.toString())));  }  /**   * Retrieves the outstanding notifications for the session user.   * @return a T containing   * notification count pairs for 'messages', 'pokes' and 'shares',   * a uid list of 'friend_requests', a gid list of 'group_invites',   * and an eid list of 'event_invites'   */  public T notifications_get()    throws FacebookException, IOException {    return this.callMethod(FacebookMethod.NOTIFICATIONS_GET);  }  /**   * Retrieves the requested info fields for the requested set of users.   * @param userIds a collection of user IDs for which to fetch info   * @param fields a set of ProfileFields   * @return a T consisting of a list of users, with each user element   * containing the requested fields.   */  public T users_getInfo(Collection<Integer> userIds, EnumSet<ProfileField> fields)    throws FacebookException, IOException {    // assertions test for invalid params    assert (userIds != null);    assert (fields != null);    assert (!fields.isEmpty());    return this.callMethod(FacebookMethod.USERS_GET_INFO,                           new Pair<String, CharSequence>("uids", delimit(userIds)),                           new Pair<String, CharSequence>("fields", delimit(fields)));  }  /**   * Retrieves the user ID of the user logged in to this API session   * @return the Facebook user ID of the logged-in user   */  public int users_getLoggedInUser()    throws FacebookException, IOException {    T result = this.callMethod(FacebookMethod.USERS_GET_LOGGED_IN_USER);    return extractInt(result);  }  /**   * Call this function to get the user ID.   *   * @return The ID of the current session's user, or -1 if none.   */  public int auth_getUserId(String authToken)    throws FacebookException, IOException {    /*     * Get the session information if we don't have it; this will populate	   * the user ID as well.	   */    if (null == this._sessionKey)      auth_getSession(authToken);    return this._userId;  }  public boolean isDesktop() {    return this._isDesktop;  }  private boolean photos_addTag(Long photoId, Double xPct, Double yPct, Integer taggedUserId,                                CharSequence tagText)    throws FacebookException, IOException {    assert (null != photoId && !photoId.equals(0));    assert (null != taggedUserId || null != tagText);    assert (null != xPct && xPct >= 0 && xPct <= 100);    assert (null != yPct && yPct >= 0 && yPct <= 100);    T d =      this.callMethod(FacebookMethod.PHOTOS_ADD_TAG, new Pair<String, CharSequence>("pid", photoId.toString()),                      new Pair<String, CharSequence>("tag_uid", taggedUserId.toString()),                      new Pair<String, CharSequence>("x", xPct.toString()),                      new Pair<String, CharSequence>("y", yPct.toString()));    return extractBoolean(d);  }  /**   * Retrieves an indicator of whether the logged-in user has installed the   * application associated with the _apiKey.   * @return boolean indicating whether the user has installed the app   */  public boolean users_isAppAdded()    throws FacebookException, IOException {    return extractBoolean(this.callMethod(FacebookMethod.USERS_IS_APP_ADDED));  }  /**   * Retrieves whether the logged-in user has granted the specified permission   * to this application.   * @param permission an extended permission (e.g. FacebookExtendedPerm.MARKETPLACE,   *        "photo_upload")   * @return boolean indicating whether the user has the permission   * @see FacebookExtendedPerm   * @see <a href="http://wiki.developers.facebook.com/index.php/Users.hasAppPermission">   *      Developers Wiki: Users.hasAppPermission</a>   */  public boolean users_hasAppPermission(CharSequence permission)    throws FacebookException, IOException {    return extractBoolean(this.callMethod(FacebookMethod.USERS_HAS_APP_PERMISSION,                                          new Pair<String, CharSequence>("ext_perm", permission)));  }  /**   * Sets the logged-in user's Facebook status.   * Requires the status_update extended permission.   * @return whether the status was successfully set   * @see #users_hasAppPermission   * @see FacebookExtendedPerm#STATUS_UPDATE   * @see <a href="http://wiki.developers.facebook.com/index.php/Users.setStatus">   *      Developers Wiki: Users.setStatus</a>   */  public boolean users_setStatus(String status)    throws FacebookException, IOException {    return extractBoolean(this.callMethod(FacebookMethod.USERS_SET_STATUS,                                          new Pair<String, CharSequence>("status", status)));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -