如何在谷歌应用程序联系人api中更改图片?

时间:2012-12-05 07:09:53

标签: java gdata-api google-contacts

* * 我想更改联系人api中的图片,但我有一些例外,请检查我的代码

String filepath="C:\\Users\\bhanuprasad\\Documents\\Downloads\\549002_459129587462191_1689883124_n.jpg";
    File file = new File(filepath);

    byte[] photoData = new byte[(int) file.length()];
String url="https://www.google.com/m8/feeds/profiles/domain/"+ sDomain + "/full/pcvita1111qaeteam10?xoauth_requestor_id=appsadmin@soharcoas.com" ;
    ContactEntry profile = contactService.getEntry(
            new URL(url),ContactEntry.class);
 GDataRequest request = contactService.createRequest(GDataRequest.RequestType.UPDATE,
          photoUrl, new ContentType("image/jpeg"));

      request.setEtag(photoLink.getEtag());
    OutputStream requestStream = request.getRequestStream();
      requestStream.write(photoData);
     request.execute();

当我调用request.execute();我得到了以下异常

com.google.gdata.util.InvalidEntryException:错误请求 图像文件无效

at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:594)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)

请帮帮我....

1 个答案:

答案 0 :(得分:0)

我没有看到任何实际读取图像的代码。您只能使用文件的长度初始化字节数组。据推测,未初始化的文件不是有效的图像。将实际的照片数据放入字节数组中,它应该可以工作。