Google Custom Search API - Engine Crash

I need to do CRUD on custom search engines. From the documentation , this looks pretty straight forward. I still get 401 responses.

I am using Google.Apis.Oauth2.v2 to get the token:

String serviceAccountEmail = "blahblahblah@developer.gserviceaccount.com";

var certificate = new X509Certificate2(@"key.p12", "blah", X509KeyStorageFlags.Exportable);

var credential = new ServiceAccountCredential(
   new ServiceAccountCredential.Initializer(serviceAccountEmail)
   {
      Scopes = new[] { "https://www.googleapis.com/auth/cse" }
   }.FromCertificate(certificate));

bool result = credential.RequestAccessTokenAsync(CancellationToken.None).Result;
TokenResponse token = credential.Token;

      

Then I add the token to the following request (authorization: Bearer mytoken):

GET http://cse.google.com/api/<USER_ID>/cse/<CSE_ID>

      

There are several things that come at me.

  • Exact quote from the documentation:

Although you can configure HTTP requests to the URL http://cse.google.com/api/ [USER_ID ]/cse/ [CSE_ID] , we recommend using instead:

http://cse.google.com/api/ [USER_ID ]/cse/ [CSE_ID]

Please note that both URLs are exactly the same.

  1. In the authentication section, the sample uses ClientLogin, which is deprecated. No samples with OAuth 2.0.

  2. The example doc says:

Each custom search engine is identified by a unique identifier created by combining the user ID with a colon-separated search engine ID, for example:

011737558837375720776: mbfrjmyam1g In this case, the user ID is 011737558837375720776 and the search engine ID is mbfrjmyam.

You would notice that the search engine ID is 2 characters long, whatever it looks like.

  1. I haven't seen an area like https://www.googleapis.com/auth/cse anywhere . "I just copied it from stackoverflow post.

I realize this is a very long question, but I hope this helps the next person to look at this and address these points.

Does anyone know why 401s?

+3


source to share





All Articles