2013-08-22 102 views
1

林附上照片到活动努力工作正常用图像到谷歌+域与新的谷歌+域API通过谷歌+域名API

发布活动发布一个活动,但是当我尝试附加照片对此,我收到一个空错误描述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) 

相同的代码,但与attachemnt线评论作品的罚款。有人设法用图像创建活动?任何线索?

在此先感谢。

回答

2

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

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

如果您要将照片附加为网址,也可以像article附件一样处理(与将网址复制/粘贴到Google+信息相同)。在这种情况下,您将使用attachment.setObjectType("article")并仅设置Url。在这种情况下,ID不是必需的。

+0

我想将照片作为URL发送。我通过“文章”改变了“照片”并开始工作。感谢提示! –