question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help with apiKey login

See original GitHub issue

I’m pretty new to google apis, and am not sure if this is an error or I’m doing something wrong (It’s probably my fault). I’m trying to get a simple API test working on my node server. This is what I have:

var google = require('googleapis');
google.options({ auth: '...myApiKey...' });
var androidpublisher = google.androidpublisher('v2');

app.get("/test3", function(req, res){
    //test googe apis
    var apiKey = "...myApiKey...";

    androidpublisher.edits.get({ editId: 1, packageName: "com.web2apptests"}, function(err, data){
        if(err){
            console.log("err:" + err);
            res.end("Look at the console.");
        }else{
            console.log(data);
            res.end("Look at the console.");
        }
    });
});

But I get the error: “Error: Login Required” I even tried with this line of code:

androidpublisher.edits.get({ auth: apiKey, editId: 1, packageName: "com.web2apptests"}, function(err, data){

What am I doing wrong? Is it possible to use androidpublisher with apiKey or does it have to be OAuth? Maybe I’m using the wrong key…

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
huzjakdcommented, Oct 17, 2016

I was clicking around a bit. Creating service accounts, adding permissions, downloading keys and in the end I ended up with the same settings as before (i think), but this time it’s working, in response I get the ID and expiry time with this code:

app.get("/test3", function(req, res){
    var key = require(__dirname + "/keys.json");
    var jwtClient = new google.auth.JWT(key.client_email, null, key.private_key, ['https://www.googleapis.com/auth/androidpublisher'], null);
    jwtClient.authorize(function(err, tokens) {
        if (err) {
            console.log(err);
            res.end("Look at the console");
            return;
        }

        androidpublisher.edits.insert({ auth: jwtClient, packageName: "com.myproject"}, function(err, resp){
            console.log(err);
            console.log(resp);
            res.end("Look at the console");
        });
    });
});
1reaction
huzjakdcommented, Oct 18, 2016

Yes, it’s working 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authenticate using API keys - Google Cloud
Sign in · Documentation · Contact Us Start free · Google Cloud · Overview. More. Solutions. More. Products. More. Pricing. More. Resources. More....
Read more >
API Keys: API Authentication Methods & Examples
There are many methods of API authentication, such as Basic Auth (username and password) and OAuth (a standard for accessing user permissions without...
Read more >
Setting up API keys - API Console Help - Google Support
To create your application's API key: Go to the API Console. ... Click Create credentials and then select API key. Note: In addition...
Read more >
Use API Keys | Maps JavaScript API - Google Developers
Go to the Google Maps Platform > Credentials page. Go to the Credentials page · On the Credentials page, click Create credentials >...
Read more >
API Keys - Swagger
Some APIs use API keys for authorization. An API key is a token that a client provides when making API calls. The key...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found