title: Retrieve info about a in-app purchase subscription of Google Play via API
body: <p>Calling Google API got this message:</p>
  
  <pre><code>    {
    "error": {
      "errors": [
        {
          "domain": "androidpublisher",
          "reason": "permissionDenied",
          "message": "The current user has insufficient permissions to perform the requested operation."
        }
      ],
      "code": 401,
      "message": "The current user has insufficient permissions to perform the requested operation."
    }
  }
  </code></pre>
  
  <p>or this error message (<strong>ADDED</strong>):</p>
  
  <pre><code>{
   "error": {
    "errors": [
     {
      "domain": "androidpublisher",
      "reason": "projectNotLinked",
      "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
     }
    ],
    "code": 403,
    "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
   }
  }
  </code></pre>
  
  <p>I follow all indications I found and I keep having this error.</p>
  
  <hr>
  
  <p><strong>ON MY SYSTEM</strong></p>
  
  <p>My code </p>
  
  <pre><code>        try {
              ini_set('max_execution_time', 3000);
              $client = new Google_Client();
  
              if ($credentials_file = $this-&gt;checkServiceAccountCredentialsFilePlay()) {
                  // set the location manually
                  $client-&gt;setAuthConfig($credentials_file);
              } elseif (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
                  // use the application default credentials
                  $client-&gt;useApplicationDefaultCredentials();
              } else {
                  $rv= "missingServiceAccountDetailsWarning()";
                  return [$rv];
              }
  
              $client-&gt;addScope("https://www.googleapis.com/auth/androidpublisher");
              $serviceAndroidPublisher = new \Google_Service_AndroidPublisher($client);
              $servicePurchaseSubscription = $serviceAndroidPublisher-&gt;purchases_subscriptions;
  
              $rv = $servicePurchaseSubscription-&gt;get(
                  "com.my.app",
                  "sub1month",
                  "ajgbkxxxxxxxxx.AO-J1OxTOKENTOKENTOKEN-"
              );
  
          } catch (\Exception $e) {
              return $e-&gt;getMessage();
          }
  </code></pre>
  
  <p>The credential file</p>
  
  <pre><code>{
    "type": "service_account",
    "project_id": "project-id",
    "private_key_id": "abababababababababababababababababa",
    "private_key": "-----BEGIN PRIVATE KEY-----KEYBASE64=\n-----END PRIVATE KEY-----\n",
    "client_email": "google-play-account@project-id.iam.gserviceaccount.com",
    "client_id": "123450000000000000000",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/google-play-account%40project-id.iam.gserviceaccount.com"
  }
  </code></pre>
  
  <hr>
  
  <p><strong>ON GOOGLE PLAY CONSOLE</strong></p>
  
  <p>I link the project to the google play console
  <a href="https://i.stack.imgur.com/AVAx1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AVAx1.png" alt="enter image description here"></a></p>
  
  <p>I add the Service account to  the google play console
  <a href="https://i.stack.imgur.com/EbwtJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EbwtJ.png" alt="enter image description here"></a></p>
  
  <p>It's present in the user menu of google play console
  <a href="https://i.stack.imgur.com/VxGY3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VxGY3.png" alt="enter image description here"></a></p>
  
  <p>And I give him all permission:
  <a href="https://i.stack.imgur.com/XHiIP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XHiIP.png" alt="enter image description here"></a></p>
  
  <hr>
  
  <p><strong>ON GOOGLE API DEVELOPER CONSOLE</strong> </p>
  
  <p><strong>ADD FYI</strong>: my "project-id" is under an organization.</p>
  
  <p>In google developer console I gave all possible permission to the service account:
  <a href="https://i.stack.imgur.com/M3qRL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M3qRL.png" alt="enter image description here"></a></p>
  
  <p>And of course I've enabled the google Play Android Developer Api (showing my failures):
  <a href="https://i.stack.imgur.com/u2bVV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u2bVV.png" alt="enter image description here"></a></p>