0

I'd like insert account my google glass, but I cann't do that.

I'm using node.js(v0.10.31), googleapis(v1.0.11) and passport-google-oauth(v0.1.5)

of course, I turned on Google Mirror API on Google Developers Console. and made pem file.

Here is google Developers console setting. (I tried to upload pics but, I need some levels.)

pkginfo.oauth.google

CLIENT ID      670282105???-a???pbnh1pp.apps.googleusercontent.com 
EMAIL ADDRESS  670282105???-????nh1pp@developer.gserviceaccount.com  
CLIENT SECRET  jt0WiP???pCwXT  
REDIRECT URIS  http://www.-----------.com:3333/auth/google/callback
JAVASCRIPT ORIGINS     http://www.-----------.com:3333
                       http://www.-----------.com
                       https://mirror-api-playground.appspot.com

.

pkginfo.oauth.glass

CLIENT ID         67028????qjv.apps.googleusercontent.com 
EMAIL ADDRESS     6702821053????qjv@developer.gserviceaccount.com 
PUBLIC KEY 
FINGERPRINTS      e25e3a045????a4e40 – Delete
                  822e7bda????e85c56 – Delete
                  70ae6e7c????45c7c9 – Delete

Here are my codes.

passport.use(new GoogleStrategy({
    clientID: pkginfo.oauth.google.CLIENT_ID,
    clientSecret: pkginfo.oauth.google.CLIENT_SECRET,
    callbackURL: pkginfo.oauth.google.REDIRECT_URL
  },
  function(accessToken, refreshToken, profile, done) {

  var googleapis = require('googleapis');
  var mirror = googleapis.mirror('v1');
  var OAuth2 = googleapis.auth.OAuth2;

  var jwt = new googleapis.auth.JWT(pkginfo.oauth.glass.EMAIL_ADDRESS,
                                  pkginfo.oauth.glass.KEY_FILE,
                                  null,//'notasecret',
  ['https://www.googleapis.com/auth/glass.thirdpartyauth'],
                                  null);

  jwt.authorize(function(err, tokens) {
    if (err) clog.error("Error @jwt.authorize:" + err);

    var oAuth2Client = new OAuth2(pkginfo.oauth.google.CLIENT_ID,
                                  pkginfo.oauth.google.CLIENT_SECRET,
                                  'postmessage');

    oAuth2Client.setCredentials({
      access_token : tokens.access_token
    })

    var params = {
      auth: oAuth2Client,
      userToken : accessToken,
      accountType : "com.cocoa.glasshelpme",
      accountName : profile.emails[0].value,
      resource :
      {
        features: ["a", "b", "c"],
        userData: [
          {key : "realName" , value : "James jerry"}
        ],
        authTokens: [
            { type: tokens.token_type, authToken: accessToken }
        ]
      }
    };

    mirror.accounts.insert(params, callback);

    function callback(err,result) {
      clog.error(err);
      clog.debug(result);
    };

and I got this error message.

error:  { errors: [ { domain: 'global', reason: 'invalid', message: 'Invalid Value' } ],
  code: 400,
  message: 'Invalid Value' }

Thank you.

j2rry
  • 3
  • 2

1 Answers1

0

Make sure you've reached out to the review team to upload your APK on MyGlass and provided them with the exact account type you are going to use (e.g com.cocoa.glasshelpme): those steps are required before you can start using this API.

You can find more information on the developers guide.

UPDATE: Just saw that you are using userToken parameter with an accessToken argument; the userToken should be the one that got provided by MyGlass when the user clicked on the auth URL.

Alain
  • 6,044
  • 21
  • 27
  • In [developers guide](https://developers.google.com/glass/develop/gdk/authentication#implementing_the_authentication_flow), Doc shows me, **@param userToken the user token sent to your auth callback URL**. But I just got param like this `code=4/TOBVkDNEWIyC4hOOC5t9n0-dk-qYjdtyWFlUkdMqMwM.otEU4oXVh_UUBrG_bnfDxpICP7VXXXXX"`, and I change this code to access_token and refresh_token, Could you let me know where can I receive is **userToken**? – j2rry Oct 27 '14 at 12:04
  • You are confusing the OAuth 2.0 web flow and GDK authentication: the former will give you a code that you need to exchange for OAuth 2.0 tokens which is completely unrelated from GDK authentication. The `userToken` is retrieved when a user clicks to install your Glassware for MyGlass: it will be part of the URL when redirecting the user to your authentication page. – Alain Oct 27 '14 at 15:52