Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot retrieve a Google Profile for editing
    primarykey
    data
    text
    <p>I'm trying to retrieve a Google Profile for editing from the Profile API using the C# .NET GData SDK but authentication seems to be failing. I'm using a number of other Google API's and can authenticate with them just fine and am using the same code approach:</p> <pre><code>var settings = new RequestSettings("appname", ApiUsername, ApiPassword); var contactsRequest = new ContactsRequest(settings); var uri = new Uri(string.Format("https://www.google.com/m8/feeds/profiles/domain/{0}/full/{1}", googleDomain, googleUsername)); var contact = contactsRequest.Retrieve&lt;Contact&gt;(uri); </code></pre> <p>I get the following exception:</p> <blockquote> <p>Google.GData.Client.GDataRequestException: Execution of request failed: <a href="https://www.google.com/m8/feeds/profiles/domain/xxx/full/joe.bloggs" rel="nofollow">https://www.google.com/m8/feeds/profiles/domain/xxx/full/joe.bloggs</a> ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.</p> </blockquote> <p>On the advice of Google Enterprise support I used their OAuth2 Playground site using the same credentials as in the code and it worked.</p> <p>My guess is that the SDK whilst taking in a username and password does not use these credentials in the RequestSettings object and authentication is failing, even though this same approach works on their Provisioning API.</p> <p>My fear is that I need to use OAuth2, which seems unecessarily complicated for what we're trying to do and there's no Google documentation to support this.</p> <p>Does anyone have any code examples of how to authenticate with the Profiles API?</p> <p><strong>Edit:</strong></p> <p>So yes, it seems I have to use OAuth2 and the Google SDK is broken as it doesn't allow you to just use username and password to authenticate. I've been hacking around with a lot of examples and am using another Google SDK that offers OAuth2 support.</p> <p>I've created a Client ID for installed applications via the API console, assigned this id API access to the scope and am using the following code:</p> <pre><code>var oAuth2Parameters = new OAuth2Parameters { ClientId = "xxx", ClientSecret = "xxx", RedirectUri = "urn:ietf:wg:oauth:2.0:oob", Scope = "https://www.google.com/m8/feeds/" }; // get an access token OAuthUtil.GetAccessToken(oAuth2Parameters); var settings = new RequestSettings("xxx", oAuth2Parameters); var contactsRequest = new ContactsRequest(settings); </code></pre> <p>This gets me further along, but now I get the following exception:</p> <blockquote> <p>System.ArgumentNullException: Value cannot be null. Parameter name: refresh_token</p> </blockquote> <p>This code is running as part of a back-end service. I don't know if the client id type of Installed Application is wrong for the type of authentication exchange. My first thought was to use the Service Account client id type, but this produced a certificate which isn't usable by the OAuth2Parameters object.</p> <p>Any helpful pointers?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload