Google contacts api (gdata) syncs low resolution photos - c#

I'm using google contacts api (gdata) to set a contact's photo in google contacts.
I'm using fiddler and I see that the request is sent according to Google Contacts Examples but the photo downloaded back from google is always 96x96.
The code I'm using to update and download the photo is:
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 syncing the contacts to my phone and there too, the size was always limited to 96x96.
Am I doing something wrong or does google not allow syncing more than 96x96? I can see many apps that do sync contacts with more than 96x96 then I guess it's possible, but what is the right way?
Edit
Here are the sync & retrieval of the photo as captured by fiddler:
Sync photo 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: Bearer myAuthorization
GData-Version: 3.0
Host: www.google.com
Content-Length: 34480
Sync photo response
HTTP/1.1 200 OK
Content-Type: application/atom+xml; charset=UTF-8; type=entry
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
Alternate-Protocol: 443:quic,p=0.01
Content-Length: 694
(Here comes xml with Id, 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; charset=UTF-8
User-Agent: G-GoogleContactsSync/GOAuth2RequestFactory-CS-Version=2.2.0.0
Authorization: Bearer myAuthorization
GData-Version: 3.0
Host: www.google.com
Photo Response:
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."
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alternate-Protocol: 443:quic,p=0.01

I retested this myself and uploaded pictures from a number of sources including contacts app on my android phone and tablet, the gmail contacts and the API. All of them will take a higher resolution picture but will only allow the size to be 96x96 using the Contact API v3.So when you download via any application using that API on the PC you will get a 96x96 image and there appears to be no way to vary that with that particular API.
Meaning unless I've also missed something that the contact API v3 is limited to this size of image. I suspect the google+ equivalents are not.
The way in which I have done this is to use the 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 are going to need to change the url that comes back to the size you want as the defaults is ?sz=50, if your original is at the size you specify it will show it or otherwise it will scale the image.
However the contacts api and the google plus api are different beasts. You will need to use the domain functionality of google plus to pull out your contacts there and potentially they have different photos than you do in your contacts list (if any is set).
Krystan

Related

How to get videoId when video is uploaded on Vimeo

How do I get the videoId after a video is uploaded on vimeo? When we call delete upload ticket, we have confirmed that the upload is successful and we are getting a response url like this url=https://api.vimeo.com/users/111243975/uploads/319650191?video_file_id=1786656414&upgrade=true&signature=4c02359068ec5a31cea3b633f6b5f9cf. Here we have video_file_id but not the actual videoId.
You're using a deprecated upload method (the "resumable" PUT method), so its documentation is no longer available on the Vimeo Developer Site. Luckily, the Internet Archive has those docs saved.
After you make the final DELETE call to that endpoint, the video uri is returned in the location header of the response.
Pow, Brow, its correct!
Location: /videos/555380765
{Connection: keep-alive
Server: nginx
Cache-Control: no-store, no-cache, private
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Location: /videos/555380765
X-RateLimit-Limit: 500
X-RateLimit-Remaining: 499
X-RateLimit-Reset: 2021-05-26T19:57:59+00:00
Request-Hash: 2461d148
X-BApp-Server: api-v10808-f5ldq
X-Vimeo-DC: ge
Accept-Ranges: bytes
Via: 1.1 varnish, 1.1 varnish
Date: Wed, 26 May 2021 19:57:00 GMT
X-Served-By: cache-bwi5155-BWI, cache-cgh11141-CGH
X-Cache: MISS, MISS
X-Cache-Hits: 0, 0
X-Timer: S1622059020.784666,VS0,VE594
Vary: Accept, Vimeo-Client-Id
Content-Length: 0
Content-Type: text/html; charset=UTF-8
}

Respond with SUCCESS in header reply

I am responding to a GET request from a field device with the following:
var reply = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
{
Content = new StringContent("SUCCESS")
};
The word appears in the message of the body. But the field device is saying that it is not successful.
From this, I can gather that I shouldn't be using HttpResponseMessage but some other means.
The suggested reply needs to look like this:
HTTP/1.1 200 OK<CR><LF>
Date: Mon, 15 Feb 2016 11:34:50 GMT<CR><LF>
Server: Apache/2.2.31 (Win32) mod_ssl/2.2.31 OpenSSL/1.0.2f PHP/5.4.45<CR><LF>
X-Powered-By: PHP/5.4.45<CR><LF>
Content-Length: 7<CR><LF>
Keep-Alive: timeout=5, max=100<CR><LF>
Connection: Keep-Alive<CR><LF>
Content-Type: text/plain<CR><LF>
<CR><LF>
SUCCESS<CR><LF>
BTW I am using Microsoft for this not PHP, this is from the manual.
Should I be using HttpRequestMessage ?
The part I am concerned with is <CR><LF>SUCCESS<CR><LF>
So the issue was that the device required a time sync with my server before it could send data later on. So there never was an issue with the response.

Microsoft Emotions API Get Recognition in Video Operation Result

How do I return the status and results from a video I posted to the emotions api using Get Recognition in Video Operation Result?
I can successfully run the Get Recognition in Video Operation Result using an operation id of a video I uploaded, but the response does not show the status of the video and the results from the emotions API but only shows the following:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent,
Headers:{
Pragma: no-cache
apim-request-id: 010962c0-f907-4ba3-a7fd-564ddff7f97d
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Cache-Control: no-cache
Date: Wed, 02 Nov 2016 02:33:16 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 16048
Content-Type: application/json; charset=utf-8 Expires: -1 }
I've tried using the same oid in the open api testing console
(https://dev.projectoxford.ai/docs/services/5639d931ca73072154c1ce89/operations/56f8d4471984551ec0a0984f/console)
and the response returns the status and the results from the emotions api.
I'm using the following code from the API reference:
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}");
var uri = "https://api.projectoxford.ai/emotion/v1.0/operations/{oid}?" + queryString;
var response = await client.GetAsync(uri);
Based on what you've pasted, it looks like you do have a response, 16048 bytes of JSON.
Since you're using C#, I think you'll save a lot of effort by using the client library, authored by members of the Cognitive Services team. If you use Visual Studio, you can simply pull down the NuGet package.
If you don't want to use the prebuilt library, you'll need to parse out the JSON yourself. The JSON will be in response.Content.

WebAPI returning File and download is not starting

Having a very strange problem, when I'am returning a file as a "HttpResponseMessage", it works when iam returning pdf file, but when I'am returning a xls file(excel file) it does not.
Here is the response headers, I've tried changing the content type to "application/vnd.ms-excel"
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 316928
Content-Type: application/octet-stream
Content-Encoding: UTF-8
Expires: -1
Server: Microsoft-IIS/8.0
Content-Disposition: attachment; filename=f.xls
Content-Description: File transfer
Charset: UTF-8
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcZGV2XHRmc1xrYmFzcnZcZUdhaW4uV2Vic2l0ZXMuRm9yZWNhc3RpbmdcYXBpXFByaW50XENhbGxpbmdMaXN0QnlDb21wYW55T3JDdXNvdG1lcklk?=
X-Powered-By: ASP.NET
Date: Fri, 06 Dec 2013 07:49:47 GMT
the result iam getting looks like when you open the xls file in notepad.
i foudn a very strange solution that was to convert it to base64 and make a link to "data: application/octet-stream; base64, "
and that would start the download thou you dont know the name of the file so the user would not understand to save it as XLS file...
now iam back at the result that wont start the download... any suggestions?
Here comes the response Raw from fiddler2
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 316928
Content-Type: application/octet-stream
Expires: -1
Server: Microsoft-IIS/8.0
Set-Cookie:
path=/; HttpOnly
Content-Disposition: attachment; filename=f.xls
Content-Description: File transfer
Charset: UTF-8
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcZGV2XHRmc1xrYmFzcnZcZUdhaW4uV2Vic2l0ZXMuRm9yZWNhc3RpbmdcYXBpXFByaW50XENhbGxpbmdMaXN0QnlDb21wYW55T3JDdXNvdG1lcklk?=
X-Powered-By: ASP.NET
Date: Fri, 06 Dec 2013 08:40:51 GMT
��ࡱ�����������������>���� ���������������d�������������������������e��f��g��h��i������������������������������������
*** FIDDLER: RawDisplay truncated at 128 characters. Right-click to disable truncation. ***
UPDATE
Iam calling the WEBAPI function with a post request, and i compare it with the old response result and they are almost the same.
iam posting the respnose from both requests here.
from the old method, the download starts...
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/vnd.ms-excel; charset=utf-8
Server: Microsoft-IIS/8.0
Content-Disposition: attachment; filename=CallList_2013-12-06.xls
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcZGV2XHRmc1xrYmFzcnZcZUdhaW4uV2Vic2l0ZXMuRm9yZWNhc3RpbmdcZUNSTVxDYWxsTGlzdEV4cG9ydC5hc3B4?=
X-Powered-By: ASP.NET
Date: Fri, 06 Dec 2013 10:11:13 GMT
Content-Length: 34590
from the new method, download dosent start.
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 316928
Content-Type: application/vnd.ms-excel; charset=utf-8
Content-Encoding: UTF-8
Expires: -1
Server: Microsoft-IIS/8.0
Content-Disposition: attachment; filename=CallList_2013-12-06.xls; charset=utf-8
Charset: UTF-8
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcZGV2XHRmc1xrYmFzcnZcZUdhaW4uV2Vic2l0ZXMuRm9yZWNhc3RpbmdcYXBpXFByaW50XENhbGxpbmdMaXN0QnlDb21wYW55T3JDdXNvdG1lcklk?=
X-Powered-By: ASP.NET
Date: Fri, 06 Dec 2013 11:04:49 GMT
UPDATE added Method where i return the result
the ByteResult class only contains byte[], contentLength, contentType and filename
protected HttpResponseMessage ByteResult(ByteResult result)
{
try
{
var responseStream = new MemoryStream();
var buffer = result.Data;
responseStream.Write(buffer, 0, Convert.ToInt32(result.ContentLenght));
// No Range header. Return the complete file.
responseStream.Position = 0;
var response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StreamContent(responseStream)
};
response.Content.Headers.Add("Content-Disposition", "attchment; filename=" + HttpUtility.UrlEncode(result.Name, Encoding.UTF8));
response.Content.Headers.Add("Content-Type", result.ContentType );
response.Content.Headers.Add("Content-Description", "File Download");
response.Content.Headers.Add("Content-Encoding", "UTF-8");
response.Content.Headers.Add("Charset", "UTF-8");
response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now);
return response;
}
catch (IOException ioex)
{
return ErrorResult(ioex, "Unknown IO Error", HttpStatusCode.InternalServerError);
}
catch (Exception ex)
{
return ErrorResult(ex, "Unknown Error", HttpStatusCode.InternalServerError);
}
}
I'd try double checking the MIME Type mappings on the client that the excel file is being downloaded to.
Also, if you change the content type in the response to application/octet-stream the client should just ask if you if you want to save the file - if the saved file is then corrupt look further into the encoding of the file.
Also look in Fiddler to ensure that the response is terminated correctly, I've previously seen files sent correctly, but then other messages tagged onto the end of the response stream due to server errors - in my case because a view didn't exist when using Monorail - so we ended up with an excel spreadsheet followed by 500 error text.
HTH,
Nick

oAuth 2.0 Google API asp.net Requesting Token

i have a problem getting token from google api, first i make this request to get code from google
accounts.google.com/o/oauth2/auth?scope=www.googleapis.com/auth/userinfo.profile www.googleapis.com/auth/userinfo.email&state=profile&redirect_uri={http://pedidostogo.com/Login.aspx}&response_type=code&client_id=519970867780.apps.googleusercontent.com&access_type=offline
this seems to be working fine (im getting a code from google) after that i make another request to get token using that code, for this i make:
accounts.google.com/o/oauth2/token?client_secret={my client secret}&grant_type=authorization_code&redirect_uri={http://pedidostogo.com/Login.aspx}&client_id={my client id}&code={code i get from google}
but when i do that POST request im getting:
Status:400 Bad Request
Headers: Pragma: no-cache
Date: Thu, 28 Feb 2013 20:00:00 GMT
Content-Encoding: gzip
X-Content-Type-Options: nosniff
Server: GSE
X-Frame-Options: SAMEORIGIN
Transfer-Encoding: chunked
Content-Type: application/json
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
X-XSS-Protection: 1; mode=block
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Data: {
"error" : "invalid_request"
}
can anyone tell me what im doing wrong? thanks.

Categories

Resources