google-api-nodejs-client


google-api-nodejs-client: how to call google+ domain api locally? (by the plusDomains.media.insert)


I am going to use the Nodejs google api client(google-api-nodejs-client) to post a photo to my google+. (I have listed all my code at end of this post.)
Let me introduce a little bit background:
I have created a project on: console.developers.google.com
I have enabled google+ domain API for this project.
I have created credentials for this project as well. (it is a OAuth 2.0 client ID)
I have a little bit experience of using the client (google-api-nodejs-client) and I can post images and files to my google drive by it.
However, posting to google+ photo is different, the auth is the key different. I have tried several different ways, but none of them works.
The api always return me this:
{ [Error: Forbidden]
code: 403,
errors: [ { domain: 'global', reason: 'forbidden', message: 'Forbidden' } ] }
I also found this:
Warning: The Google+ Sign-In button and the plus.login scope used by
Google+ Sign-In, are not currently supported for use with the Google+
Domains API. Requests that are made to the Google+ Domains API using
an authentication token granted for the
www.googleapis.com/auth/plus.login scope, or generated by the
Google+ Sign-In button, will fail.
If it doesn't support the sign-button, what does it support?
This page tell me to add a domain delegation (https://developers.google.com/+/domains/authentication/delegation), but i haven't push my program into any server, i just try to run it locally.
I was wondering if it is possible to use this client to post photo to google+ by run a nodejs program locally?
var CLIENT_ID = "xxxxxxx.apps.googleusercontent.com";
var CLIENT_SECRET = "xxxxxxxx";
var REDIRECT_URL = "https://xxxxxxx";
var readline = require('readline');
var async = require('async');
var google = require('googleapis');
var request = require('request');
var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function getAccessToken (oauth2Client, callback) {
// generate consent page url
var scopes = [
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/plus.stream.read',
'https://www.googleapis.com/auth/plus.stream.write',
'https://www.googleapis.com/auth/plus.circles.read',
'https://www.googleapis.com/auth/plus.circles.write',
'https://www.googleapis.com/auth/plus.media.upload'
];
var url = oauth2Client.generateAuthUrl({
access_type: 'offline', // 'online' (default) or 'offline' (gets refresh_token)
scope: scopes, // If you only need one scope you can pass it as string,
key: 'p7UALH460Deqodhvb2zESYya'
});
console.log('Visit the url: ', url);
rl.question('Enter the code here:', function (code) {
// request access token
oauth2Client.getToken(code, function (err, tokens) {
if (err) {
return callback(err);
}
// set tokens to the client
// TODO: tokens should be set by OAuth2 client.
oauth2Client.setCredentials(tokens);
console.dir(tokens);
callback();
});
});
}
getAccessToken(oauth2Client, function () {
var plusDomains = google.plusDomains({ version: 'v1', auth: oauth2Client });
var requestObj = request({url:'http://asset1.cxnmarksandspencer.com/is/image/mands/2643f540b32fe8c6cccdec95b3a2c5239166232f?$editorial_430x430$'});
const Readable = require('stream').Readable;
var iamgeStream = new Readable().wrap(requestObj);
plusDomains.media.insert({
userId: 'me',
collection: 'cloud',
resource: {
name: 'testimage.png',
mimeType: 'image/png'
},
media: {
mimeType: 'image/png',
body: iamgeStream
},
access:{domainRestricted :"true"}
}, callbackFn);
function callbackFn(argument) {
console.dir(argument);
}
});
Thanks you very much!
Peter

Related Links

Connecting to google v2 api sandbox using nodejs sdk google-api-nodejs-client
Difference between Javascript and Node.js version of Google Slides API
Accessing Google Api using Nodejs
google-api-nodejs-client: how to call google+ domain api locally? (by the plusDomains.media.insert)
Node.js Consuming a RESTful service application using MVC
Can't retrieve the play store reviews for my app
Prediction request end up with “invalid data” errors
google oauth2 implementation using Node JS error
Error 500 backendError with Gmail API and Google APIs Node Client
How can Dimensions be included in the API call object?
“npm install googleapis” produces the following error
Google Calendar API NodeJS - specify fields
How to make POST API calls with google-api-nodejs-client?
drive.comments.insert worked with previous version, not current

Categories

HOME
xamarin
client
gerrit
proxy
google-play
routes
jira
infragistics
graphql
sqlite3
binary-tree
win32gui
angular-ui-bootstrap
swagger-ui
google-translate
dax
ibm-odm
seaborn
after-effects
transformation
crystal-reports-2008
plunker
abi
tar
ehcache
trading
tdd
spark-jobserver
applozic
saas
objectanimator
quote
unboundid
microsoft-chart-controls
frame
android-kernel
environment-modules
objectlistview
trim
ensembles
appcompat
python-webbrowser
kbuild
color-profile
word-vba-mac
removechild
qpid
bluemix-app-scan
wso2cloud
intellij-14
ruby-2.2
mutation-observers
computer-algebra-systems
embedded-code
emailrelay
nsight
unity3d-gui
python-green
typekit
internet-connection
php-5.4
android-radiobutton
heisenbug
starcluster
phpthumb
doskey
hippomocks
mysql-error-1062
mysqltuner
c18
sabredav
enterprisedb
itmstransporter
sublist
word-processor
osql
fireworks
psi
winbugs14
google-friend-connect
gallio
mozilla-prism
thunderbird-lightning
meego
ctp4
temporal-database
zend-decorators
spec#
post-build
uiq3

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App