0

我想插入我的谷歌玻璃帐户,但我不能这样做。如何插入帐户我的谷歌玻璃使用node.js

我如何使用Node.js(v0.10.31),googleapis(v1.0.11版)和护照谷歌-的OAuth(v0.1.5)

当然

,我打开谷歌镜像APIGoogle Developers Console。并作了pem文件。

这里是谷歌开发者控制台设置。 (我试着上传图片,但我需要一些的水平。)

pkginfo.oauth.google 

CLIENT ID  670282105???-a???pbnh1pp.apps.googleusercontent.com 
EMAIL ADDRESS [email protected] 
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  [email protected] 
PUBLIC KEY 
FINGERPRINTS  e25e3a045????a4e40 – Delete 
        822e7bda????e85c56 – Delete 
        70ae6e7c????45c7c9 – Delete 

这是我的代码。

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); 
    }; 

我得到了这个错误信息。

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

谢谢。

回答

0

请确保您已联系审核团队以在MyGlass上上传APK,并为他们提供准备使用的帐户类型(例如com.cocoa.glasshelpme):在开始使用此API之前,需要执行以下步骤。

您可以在developers guide找到更多的信息。

UPDATE:刚刚看到您使用的参数为userToken,参数为accessToken; userToken应该是用户点击auth URL时由MyGlass提供的。

+0

在[开发者指南](https://developers.google.com/glass/develop/gdk/authentication#implementing_the_authentication_flow)中,Doc展示了我,** @param userToken将用户令牌发送到您的auth回调URL ** 。但我刚刚得到了这样的代码:“code = 4/TOBVkDNEWIyC4hOOC5t9n0-dk-qYjdtyWFlUkdMqMwM.otEU4oXVh_UUBrG_bnfDxpICP7VXXXXX”',我将此代码更改为access_token和refresh_token,您可以让我知道我可以在哪里收到** userToken **? – j2rry 2014-10-27 12:04:31

+0

You正在混淆OAuth 2.0 Web流程和GDK认证:前者会为您提供一个代码,您需要交换OAuth 2.0令牌,这与GDK身份验证完全无关。当用户单击以安装您的Glassware for MyGlass:将用户重定向到认证页面时,它将成为URL的一部分。 – Alain 2014-10-27 15:52:49