2

关于如何通过在 java 中使用新的 google+ 域的 API 列出我域中的所有活动的任何想法?

开发人员的现场视频显示在 4:00 分钟标记您可以执行以下操作:

Plus.Activities.List listActivities = plus.activities().list("me", "domain");

此代码的链接在这里

但是当我实际运行同一行代码时,它会显示以下错误。

{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "location" : "collection",
    "locationType" : "parameter",
    "message" : "Invalid string value: 'domain'. Allowed values: [user]",
    "reason" : "invalidParameter"
  } ],
  "message" : "Invalid string value: 'domain'. Allowed values: [user]"
}

该错误是有道理的,因为在activities.list 文档中它说“用户”是唯一可接受的集合值,而不是“域”。

那么这个问题我该怎么办呢?

4

3 回答 3

1

正如您所说,唯一可用的方法是列出当前登录用户的帖子。您必须使用用户委托(使用服务帐户)并遍历域中的所有用户才能获得所有已发布的活动。

您可以使用updated响应中的字段来检查用户的活动列表中是否有任何新内容。

这种思路适用于整个 Domains API:每一个操作都是代表一个用户完成的,没有拥有超能力的“管理员”帐户。当对大量用户进行操作时,这可能是一个限制,因为您被迫依次为每个用户进行身份验证(如果有人知道如何以更有效的方式实现这一点,请分享!)

于 2013-08-22T13:13:44.160 回答
0

当您使用 Google+ API 时,您必须使用“public”,但当您使用 Google+ Domains API 时,您必须使用“user”参数值。

于 2014-11-23T00:06:49.217 回答
0

正如文档所说,只允许“公开”:

https://developers.google.com/+/api/latest/activities/list

但是,即使使用 API 文档中示例中提供的代码,在通过成功的身份验证后,我也会得到 0 个活动。

 /** List the public activities for the authenticated user. */
  private static void listActivities() throws IOException {
    System.out.println("Listing My Activities");
    // Fetch the first page of activities
    Plus.Activities.List listActivities = plus.activities().list("me", "public");
    listActivities.setMaxResults(100L);
    // Pro tip: Use partial responses to improve response time considerably
    listActivities.setFields("nextPageToken,items(id,url,object/content)");

    ActivityFeed activityFeed = listActivities.execute();
    // Unwrap the request and extract the pieces we want
    List<Activity> activities = activityFeed.getItems();
    System.out.println("Number of activities: " + activities.size());
    // Loop through until we arrive at an empty page
    while (activities != null) {
      for (Activity activity : activities) {
        System.out.println("ID " + activity.getId() + " Content: " +
                activity.getObject().getContent());
      }

      // We will know we are on the last page when the next page token is null.
      // If this is the case, break.
      if (activityFeed.getNextPageToken() == null) {
        break;
      }

     // Prepare to request the next page of activities
      listActivities.setPageToken(activityFeed.getNextPageToken());

      // Execute and process the next page request
      activityFeed = listActivities.execute();
      activities = activityFeed.getItems();
    }
}

有人知道如何让它工作吗?

于 2013-12-21T16:54:35.893 回答