2013-08-22 98 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發送。我通過「文章」改變了「照片」並開始工作。感謝提示! –