1

我正在尝试使用新的 google + 域 API 将带有图像的活动发布到 google+ 域

发布活动工作正常,但是当我尝试将照片附加到它时,我收到一个 500 错误,描述为空。

这是代码:

String msg = "Activity with photo";

// Create a list of ACL entries
PlusAclentryResource resource = new PlusAclentryResource();
resource.setType("domain"); // Share to domain

List<PlusAclentryResource> aclEntries = new ArrayList<PlusAclentryResource>();
aclEntries.add(resource);

Acl acl = new Acl();
acl.setItems(aclEntries);
acl.setDomainRestricted(true);  // Required, this does the domain restriction

// Create a new activity object
Activity activity = new Activity()
    .setObject(new Activity.PlusObject().setOriginalContent(msg))
    .setAccess(acl);

// Attach the link
Activity.PlusObject.Attachments attachment = new Activity.PlusObject.Attachments();
attachment.setObjectType("photo");
attachment.setUrl( "http://c299813.r13.cf1.rackcdn.com/MuseeduLouvre_1335428699_org.jpg" );
attachment.setId( randomId ); //if not specified, google returns an error with "you must specify the photo id"

List<Activity.PlusObject.Attachments> attachments = new ArrayList();
attachments.add(attachment);    // You can also add multiple attachments to the post
activity.getObject().setAttachments(attachments);

activity = plus.activities().insert("me", activity).execute();

当代码调用执行时,我收到此错误:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 500
{
  "code": 500,
  "message": null
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)

相同的代码,但带有注释的附件行可以正常工作。有人设法用图像创建活动吗?任何线索?

提前致谢。

4

1 回答 1

2

无法通过 URL 直接附加照片。该过程的工作方式略有不同,如下所述:https ://developers.google.com/+/domains/posts/attaching-media

如果您没有照片的实际二进制数据,您首先必须“下载”照片。然后您可以通过该方法上传实际的照片数据media().insert,这将为您提供照片 ID,然后您可以在attachment.setId(). setUrl在这种情况下没有必要。

如果您想将照片作为 URL 附加,也可以像article附件一样处理(就像您将 URL 复制/粘贴到 Google+ 帖子中一样)。在这种情况下,您将使用attachment.setObjectType("article")并且仅设置 Url。在这种情况下,id 不是必需的。

于 2013-08-22T10:24:31.907 回答