Google contacts api (gdata) sync low resolution photos

I am using google contacts api (gdata) to set a contact photo in google contacts.
I use a violinist, and I see that the request is sent in accordance with the examples of Google contacts , but the photo is loaded with google site, is always equal to 96x96.
The code I am using to update and download the photo:

public void UpdateUserPhoto(Contact contact, Stream photo)
{
      _contactsRequest.SetPhoto(contact, photo);
}

public static void DownloadPhoto(ContactsRequest cr, Contact contact)
{
    if (contact.PhotoEtag == null)
        return;
    Stream photoStream = cr.Service.Query(contact.PhotoUri);
    FileStream outStream = File.OpenWrite(string.Format(@"c:\friends\{0}.jpg",contact.Name.FullName));
    byte[] buffer;
    using (var memoryStream = new MemoryStream())
    {
        photoStream.CopyTo(memoryStream);
        buffer =  memoryStream.ToArray();
    }

    outStream.Write(buffer, 0, buffer.Length);
    photoStream.Close();
    outStream.Close();
}

      

I tried to sync contacts with my phone, and there, too, the size was always limited to 96x96. Am I doing something wrong or is Google not allowing sync more than 96x96? I see a lot of apps that sync contacts over 96x96, then I guess it is possible, but what is the correct way?

Edit

Here is the sync and extract of a photo taken by a violinist:
Photo sync request:
PUT https://www.google.com/m8/feeds/photos/media/ mymail@gmail.com / 55f3484e8aaf1c82 HTTP / 1.1
Etag: "SomeEtag"
If- Match: "SomeEtag."
Content-Type: image / jpg
User-Agent: G-GoogleContactsSync / GOAuth2RequestFactory-CS-Version = 2.2.0.0
Authorization: Transfer MyAuthorization
GData-Version: 3.0
Host: www.google.com
Content-Length: 34480

Synchronize photo reaction
HTTP / 1.1 200 OK
Content-Type: application / atom + xml; encoding = UTF-8; type = record
GData-Version: 3.1
ETag: "KgxxHGIyfCt7I2BoA047FShUNFU3BWx8RDQ."
Date: Wed, 01 Oct 2014 20:13:06 GMT
Expires: Wed, 01 Oct 2014 20:13:06 GMT
Cache-Control: private, max-age = 0
X-Content-Type-Options: nosniff
X-Frame- Options: SAMEORIGIN
X-XSS-Protection: 1; Mode = block
Server: GSE
Alternative protocol: 443: quic, p = 0.01
Content-length: 694
(Here comes the xml with the identifier, updated, edited, etc.)

Photo request:
GET https://www.google.com/m8/feeds/photos/media/ mymail@gmail.com / 55f3484e8aaf1c82 HTTP / 1.1
Content-Type: application / atom + xml; encoding = UTF-8
User-Agent: G-GoogleContactsSync / GOAuth2RequestFactory-CS-Version = 2.2.0.0
Authorization: Passing MyAuthorization
GData-Version: 3.0
Host: www.google.com

Reply to photo:
HTTP / 1.1 200 OK
Content-Type: image / jpeg
Expires: Wed, 01 Oct 2014 20:25:54 GMT
Date: Wed, 01 Oct 2014 20:25:54 GMT
Cache-Control: private, max-age = 0, must-revalidate, no-transform
Vary: Accept, X-GData-Authorization, GData -Version
GData-Version: 3.1
ETag: "SomeEtag".
Transmission coding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; Mode = block
Server: GSE
Alternative protocol: 443: quic, p = 0.01

+3


source to share


1 answer


I tried this myself again and downloaded photos from multiple sources including contacts app on my android phone and tablet, gmail contacts and API. They will all have a higher resolution image, but allow 96x96 with Contact API v3.So when loaded through any application using this API on a PC you will get a 96x96 image and there seems to be no way to change that with this particular API.

Meaning, if I haven't also missed something, that the v3 API contact is limited to this image size. I suspect the google + equivalents are not.

The way i did it is using google plus api

  var service = new PlusService(new BaseClientService.Initializer());
  var request = new PeopleResource.GetRequest(service, "<your google user id>")
  {
      OauthToken = authParameters.AccessToken
  };

  Person person = request.Execute();
  Person.ImageData image = person.Image;
  string pictureUrl = image.Url;

  ... request to url here after munging sz

      



now you will need to change the url that falls back to the size you want as the defaults are: sz = 50, if your original is in the size you specified it will show it or otherwise scale the image.

However, the api and google plus api contacts are different beasts. You will need to use the google plus domain functionality to pull your contacts there, and maybe they have different photos than in your contact list (if installed).

Krystan

+3


source







All Articles