title: How to authorize google cloud vision API android
body: <p>I am implementing google cloud vision API from this <a href="https://cloud.google.com/vision/" rel="nofollow noreferrer">link</a>.</p>
  
  <p>Below is my code where I am getting exception:</p>
  
  <pre><code>private void callCloudVision(final Bitmap bitmap) throws IOException {
      new AsyncTask&lt;Object, Void, String&gt;() {
          @Override
          protected String doInBackground(Object... params) {
              try {
                  List&lt;AnnotateImageRequest&gt; requests = new ArrayList&lt;&gt;();
                  ByteArrayOutputStream bos = new ByteArrayOutputStream();
                  bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
                  byte[] bitmapdata = bos.toByteArray();
                  ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
                  ByteString imgBytes = ByteString.readFrom(bs);
                  Image img = Image.newBuilder().setContent(imgBytes).build();
                  Feature feat = Feature.newBuilder().setType(Feature.Type.WEB_DETECTION).build();
                  AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
                  requests.add(request);
  
                  ***//Getting exception here at the time of execution...***
                  try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
                      BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
                      List&lt;AnnotateImageResponse&gt; responses = response.getResponsesList();
                      for (AnnotateImageResponse res : responses) {
                          if (res.hasError()) {
                              System.out.printf("Error: %s\n", res.getError().getMessage());
                              return "";
                          }
                          System.out.println("\nPages with matching images: Score\n==");
                          for (WebDetection.WebPage page : annotation.getPagesWithMatchingImagesList()) {
                              System.out.println(page.getUrl() + " : " + page.getScore());
                          }
                      }
                  }
  
                  return "";
  
              }  catch (Exception e) {
                  Log.d("LOG_TAG", "Request failed: " + e.getMessage());
                  return "Cloud Vision API request failed.";
              }
  
          }
  
          protected void onPostExecute(String result) {
  
          }
      }.execute();
      }
  </code></pre>
  
  <p>I am getting error </p>
  
  <blockquote>
    <p>java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See <a href="https://developers.google.com/accounts/docs/application-default-credentials" rel="nofollow noreferrer">https://developers.google.com/accounts/docs/application-default-credentials</a> for more information.</p>
  </blockquote>
  
  <p>My graddle</p>
  
  <pre><code>implementation 'com.android.support.constraint:constraint-layout:1.0.2'
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:26.+'
  **compile 'com.google.cloud:google-cloud-vision:1.21.0'**
  compile group: 'com.google.apis', name: 'google-api-services-sqladmin', version: 'v1beta4-rev52-1.23.0'
  compile('com.google.api-client:google-api-client-android:1.22.0') {
      exclude module: 'httpclient'
      exclude group: 'com.google.guava'
  }
  compile('com.google.http-client:google-http-client-gson:1.20.0') {
      exclude module: 'httpclient'
      exclude group: 'com.google.guava'
  }
  </code></pre>