I'm trying to user tumblr.js to create some photo post containing multiple images (from url). The method works fine when I use source (hence with a single url), but stop working when I try using data instead of source to send multiple photos at the same time.
My code is pretty basic for the moment but is still not working :
client.createPhotoPost('myblog.tumblr.com', {data: ['http://www.gstatic.com/webp/gallery/1.jpg'] },
function (err, data) {
console.log("CREATE PHOTO POST", err, data)
});
The error is API error: 401 Unauthorized which does not seem to be relevant.
Does anyone has already used this and has any idea how to fix it ?
Related
What I am using - EJS, JS, NODE, Express.
I am new to this and have been getting away with googling stuff so far.
So I am making a website and I want it to be unique for every new tab. Right now, if one person clicks a button that displays a message, and I go to a different tab and open the link, I can see the message that the first person set. I read something about express-session and session Id and sending the requests through the sessionID to make sure it is sent to the right person. But I don't know how to implement them here
EDIT: Here is my best attempt trying to make sense out of this.
router.post("/", (req, res, next) => {
Actors.find({}, (err, actorFound) => {
if (err) {
throw err
} else {
res.render("welcome", {
actors: actorFound,
findItems: suggested
})
}
})
})
When I "call" this on local host it would basically dump everything from the data base. Which is what it is supposed to do. However, if I open localhost using a different web browser, (trying to simulate a different visitor) I would find that my data from actors is already dumped on the page. Does this make sense. I will try to explain anything specific if you have any question and thank you very much.
I am trying to send a POST request with query parameters using the request library. I have succeded in sending these requests, but I am still unable to include any working query.
I have followed instructions from other posts and concluded that I’ve tried everything on the internet that is related to my mission.
This is the code that does comply with what I found on the internet:
const request = require(’request’);
request.post({
url: 'https://example.com/endpoint',
qs: { with_counts: true } },
function (err, res, body) {
console.log(err, body);
}
);
This, however, does not work. The server does not recieve the query. I tried setting the body and json properties instead, but those didn’t work either.
I cant tell what I’m doing wrong, and I realize that it might not be possible for you to tell, but this is my last desperate attempt before giving up and switching to Python.
I'm getting an error while trying to delete a field from a mongo database I created in an API project I'm working on. I'm still very much new to not only RESTful APIs but also MongoDB and Express. I followed a tutorial on Youtube that explained the steps to go through to make such an API and so I did and everything worked perfectly. Now I'm trying to reproduce this API using my own custom fields.
Basically my database is populated with two elements right now. I've already created get, add and update methods that work properly. Here is the response for the get method :
[{"_id":"58a112564cb325769b9d90de","name":"John Doe","caption":"I like pizza","friends":["id1","id2","id3"],"schedule":[[13,14],[14,15.5]]},{"_id":"58a1178da52bfc07fd25ce3f","name":"Carla Doe","caption":"I hate pizza","__v":0,"friends":null,"schedule":null}]
Now the function that has an issue is the delete function. I can't seem to find what might be wrong with it. It is the exact same function as in the aformentioned Youtube tutorial. I've checked a hundred times over, there is no character wrong or missing.
Here is the error I get in postman :
Cannot DELETE /api/clients/58a1178da52bfc07fd25ce3f
Here is the server.js part :
// Delete client
app.delete('api/clients/:_id', function(req, res){
var id = req.params._id;
Client.deleteClient(id, function(err, client){
if(err){
throw err;
}
else {
res.json(client);
}
});
});
Here is the clients.js part :
// Delete Clients
module.exports.deleteClient = function (id, client, callback) {
var query = {_id: id};
Client.remove(query, client, callback);
};
I don't know if I'm giving you all the information needed to resolve the issue. I can't for the love of me find out where it's coming from.
Looking forward to read your answers.
I think a '/' is missing before '/api/clients/:_id'
it should be :
app.delete('/api/clients/:_id', function(req, res)
there is a website that works with virtual items for an online game. I made a chrome extension that automates some actions on that website. Since I'd like to make this run on my raspberryPi (and chromium with the extension seems to be too slow and unefficient) I am trying to move this into node.js.
The login for the website works with Steam OpenID. It allows you to select items from a list, click a few buttons, then it sends you a tradeoffer on steam.
My extension works with the website while I was logged in there. It receives their database with jQuery getJSON, loops through the array, pushes some values into an array and then sends a post request telling the website which items I want and which items I am offering.
Here is how I am sending the request from chrome:
function withdrawXHR(botId, playerItems, botItems) {
$.ajax({
url: websiteURL,
type: 'post',
data: {
"steamid": botId,
"peopleItems": playerItems,
"botItems": botItems
},
success: function (data) {
console.error('>> Done: ' + data)
console.log("")
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.error('>> Error: ' + errorThrown)
console.log("")
}
});
}
I can do everything in node so far like receiving their database, working through it, filter out the values I need, but I can't manage to send a working request. The problem is probably the login / how the website knows who I am.
I used wrapAPI (a chrome extension) to catch the request that is being sent when manually working with the website. Here is what it looks like:
So these are the things I am wondering about:
How would I send this request from node?
How does the website know who I am? They obviously know, because they are sending me an offer, but I can't see any "personal" data in that request.
Would I need to log into Steam OpenId from Node in some way? Is that possible?
What is a CF-RAY? (See the end of the captured request).
I am quite new to JS and requests in general and even "newer" to Node.js. I don't fully understand how the background of sending requests works. I would just need some tips, ideas on how to achieve my goal here.
Any help is greatly appreciated! Thank you! :)
You cannot use XMLHttpRequest for resources across domains. ( incidentally, unless you are using an extension)
I would look into grabbing express.js, and something called CORS. CORS permits cross-domain requests.
Here: http://enable-cors.org/server_expressjs.html
And here is some information on XHR requests in browser extensions: https://developer.chrome.com/extensions
I have a nodejs (+express + mongodb,gridstore) backend, and want to upload a photo to a facebook album.
I came across 2 methods. the first ( https://developers.facebook.com/blog/post/526/ ) needs to get the full url resource of my picture, which I don't have as it is data that I pull from gridstore,
and the second ( https://developers.facebook.com/docs/reference/api/album/ ) is very poorly documented, via the Graph API, where I can't figure out what my request should look like. (the form-data, what fields should it have, how to convert my data blob\stream from gridstore to it)
Here is what I currently have, and doesn't work:
facebook.uploadPhoto = function (token, albumId, photo, callback) {
var fb = fermata.json('https://graph.facebook.com/' + albumId);
fb.photos({access_token:token}).post({'Content-Type':"multipart/form-data"}, {source:{data:photo}}, callback);
};
Any help would be much appreciated
There is a good chance the file is not properly serialized. Fermata will take a node File buffer via data. Have you tried passing that instead?
fs.readFile("/path/to/photo.jpg", function (err, data) {
fermata.json("https://graph.facebook.com/graph/api").post({"Content-Type":"multipart/form-data"}, {fileField: {data:data, name:"", type:""} }, callback);
});
Adding your access token etc..
I solved this problem by using a simple POST to the facebook graph API using the poster module.
var options = {
uploadUrl: 'https://graph.facebook.com/'+user+'/photos?access_token='+accessToken,
method: 'POST',
fileId: 'source',
fields: {'message':''} // Additional fields according to graph API
};
var fileName = ''; // Local or remote url where to find the image
poster.post(fileName, options, function(err, data) {
if (err) {
//Something went wrong
} else {
// Everything ok
}
});
Honestly, I've got limited experience working with the Facebook graph API and mostly using PHP and Java.
Here is some streams that you might find helpful:
Upload Photo To Album with Facebook's Graph API
Facebook Graph API - upload photo using JavaScript
Basically, I recommend you punt a little in your implementation and code it in the following way:
Create a REST web service function call in Node.js to output a single image from gridstore using an internal UID.
Code your uploadToFacebook function to use an image URL that calls the REST web service function.
Basically, this would allow you to validate the image output by pointing your browser to the REST web service and avoid any blob\stream conversions inside your uploadToFacebook function. I'm assuming you store the image in gridstore vs. mongodb.
hope that helps...