unofficial vine api not working - node.js

I am trying to connect to the vine API to retrieve the list of uploaded videos of a given user.
I'm using a node.js module called Vineapple.
The problem is some of the api endpoints seems to not work anymore
Here is a snippet that works
var vine = new vineapple({
key: 'some-key',
userId: '123456789',
username: 'user',
});
vine.me(function(err, response){ // calls 'https://api.vineapp.com/users/me'
if(err) throw err;
console.log(response);
});
This logs the whole vine user's settings:
{ followerCount: 300,
includePromoted: 2,
userId: '123456789',
private: 0,
likeCount: 30,
... etc }
And here is a snippet that does not work
var vine = new vineapple({
key: 'some-key',
userId: '123456789',
username: 'user',
});
vine.user(connectionObject.userId.toString(), function(err, response){ // calls 'https://api.vineapp.com/timelines/users/{userId}'
if(err) throw err;
console.log(response);
});
This never return anything.
Are all the vine api endpoints still available?
If yes, what could be my problem?
If no, is there another solution to retrieve vine videos?
Thanks

For those who are wondering.
As for today (april 2014), the vine unofficial api is still up. You can test it if here : https://api.vineapp.com/timelines/users/920890957405237248
I had a problem with the node.js vineapple module:
1/ You should always call vineapple functions with promise syntax:
https://github.com/furf/vineapple#promises
2/ Vine use big int as user ids, js cannot handle those so you should send userId as js strings and not numbers (I stored it as ints. The .toString() was useless here)
3/ There is a known bug in vineapple module, you should comment line 121 of vineapple.js: https://github.com/furf/vineapple/issues/2
As a conclusion, here is how my code look like:
var vine = new vineapple({
key: key,
userId: userId, // Stored as String !
username: username,
});
options= {page: '1', size: '20'};
vine.user(userId, options).then(function (response) {
console.log('SUCCESS', response);
}).fail(function (error) {
console.log('ERROR', error);
});
Hope it helps

Related

nodejs gmail api not supporting promises

Google recommends using promises, but its code examples do not, and I'm struggling to make the gmail api work with promises when I modify the code from the online docs.
All I've changed are the lines below, but I get an error
VM677:5 Uncaught TypeError: gmail.users.messages.list(...).then is not a function
gmail.users.messages.list({
auth: auth,
userId: 'me',
labelIds: 'Label_14'
// }, function(err, response) {
// if (err) {
// console.log('The API returned an error: ' + err);
// return;
// }
// console.log(response);
})
.then(response => {
console.log("success", response);
})
Most of the examples of SO use promises so I think it should be possible but I can't see what the problem is. Would really welcome some help
The googleapis module does not support promises.
Consider using util.promisify if you want to use promises with this module.
var list = util.promisify(gmail.users.messages.list);
list({
auth: auth,
userId: 'me',
labelIds: 'Label_14'
})
.then(...);

How can I get a list of emails sent from a particular person?

I am using the Google Gmail API to get a list of messages. What I would like to do is get a list of all the messages that have been sent from a particular user. Here is what I have so far:
var oauth2Client = new OAuth2('', '', '');
oauth2Client.setCredentials(token);
var gmail = google.gmail('v1');
gmail.users.messages.list({
auth: oauth2Client,
userId: 'me'
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
cb(null, false);
} else {
cb(null, response);
}
});
I tried setting userId: 'person#email.com' but that gave me the following error:
The API returned an error: Error: Delegation denied for person#email.com
What am I missing? Thanks ahead of time for any answers!
You should use q parameter with value like this: from:person#email.com. It would filtrate emails by from header.
Then you are trying to use userId: 'person#email.com Google API thinks that you want a list of emails from person#email.com inbox (but you do not have access to it).

Node: Google Drive API for listing all files using query

May I know how can I list all the files using query in the Google Drive using the GoogleAPIS library
https://github.com/google/google-api-nodejs-client/
I have no idea, how to use this library!
I dont know where should I place my query, I have tried the code below, but I am not getting any response..
Test 1:
drive.files.list("mimeType='image/jpg'", function(data){
//I am getting all the data, the query is not working..
));
Test 2:
drive.files.list({
media: {
mimeType: 'application/vnd.google-apps.folder'
}
}, function(err, data){
//I am getting all the data, the query is not working..
});
Test 3:
drive.files.list({
resource: {
mimeType: 'application/vnd.google-apps.folder'
}
}, function(err, data){
//This returns error not working at all!
});
You can check the drive.files.list function given here https://github.com/google/google-api-nodejs-client/blob/master/apis/drive/v2.js#L733 and use something like the following for it.
var drive = google.drive({ version: 'v2', auth: oauth2Client });
drive.files.list({
q='mimeType='image/jpg''
}, callback);
More details on the input parameters for the list function are on https://developers.google.com/drive/v2/reference/files/list

Does the Gmail API support JWT?

I want to access the Gmail API using NodeJS.
I'm using a server-to-server approach (see this) but when I execute the code below, I get a backEndError, code 500 from the Google API.
Any ideas?
var authClient = new google.auth.JWT(
'email',
'key.pem',
// Contents of private_key.pem if you want to load the pem file yourself
// (do not use the path parameter above if using this param)
'key',
// Scopes can be specified either as an array or as a single, space-delimited string
['https://www.googleapis.com/auth/gmail.readonly']
);
authClient.authorize(function(err, tokens) {
if (err)
console.log(err);
gmail.users.messages.list({ userId: 'me', auth: authClient }, function(err, resp) {
// handle err and response
if (err) {
console.log(err);
});
Yes, I have the same problem. If I use the scope "https://mail.google.com", I get
403
{
"error" : "access_denied",
"error_description" : "Requested client not authorized."
}
And if I use the scope "https://mail.google.com/" (notice the / at the end), I get
403
'Forbidden'
It seems to be related to using JWT and service account.

Sending JSON error from Node.js backend to iPhone frontend: "Error: Can't set headers after they are sent."

I'm new to Node.js. I'm using it as a server backend to an iPhone client. I'm calling a POST with the JSON: {firstname: "bob", email : bob#someemail.com}
The node.js code looks like this (using Express and Mongoose):
var User = new Schema({
firstname : { type: String, required: true}
, email : { type: String, required: true, unique : true}
});
var User = mongoose.model('User', User);
And for the POST,
app.post('/new/user', function(req, res){
// make a variable for the userData
var userData = {
firstname: req.body.firstname,
email: req.body.email
};
var user = new User(userData);
//try to save the user data
user.save(function(err) {
if (err) {
// if an error occurs, show it in console and send it back to the iPhone
console.log(err);
res.json(err);
}
else{
console.log('New user created');
}
});
res.end();
});
Right now, I'm trying to create duplicate users with the same email. I expect this to throw an error due to the "unique" constraint I have on the email -- which it does.
However, the node.js process dies with, "Error: Can't set headers after they are sent."
I would like to be able to send a message back to the iPhone client in scenarios such as these. For example, in the above, I'd like to be able to send back JSON to the iphone saying the result of the new user creation (successful or failed).
Thank you!
It's because the asynchronous nature of your code. The res.end() runs before the callback function of user.save you should put the res.end()inside that callback ( at the end).
this way:
user.save(function(err) {
if (err) {
// if an error occurs, show it in console and send it back to the iPhone
console.log(err);
return res.json(err);
}
console.log('New user created');
res.end();
});
Send your error using an appropriate http status, you have plenty of 4xx to do that.
res.json(420, err);
That way, you will just have to parse the message in your http fetch, with jquery it gives something like :
jQuery.ajax({
...
error: function (xhr, ajaxOptions, thrownError) {
if(xhr.status == 420) {
JSON.parse(xhr.responseText);
}
}

Resources