I am trying to download a file from Google Drive to my harddrive. The entire authentication is done in JavaScript and I am receiving a response from the server:
request = gapi.client.drive.files.get({'fileId': id});
request.execute(function(resp) { ........ }
I have the correct scope in order to be allowed to download files:
https://www.googleapis.com/auth/drive
Also the request above is returning me a downloadUrl.
I am trying to send the downloadUrl to PHP, but the download process is failing with a 401 error.
Any suggestion? I have tried to download the file directly in Javascript, but I didn't find a good solution yet.
Thanks and let me know if you have any question.
It is my first question here since this one is killing me :D
Is this a public file or a private file? Are you sending the right auth token to GDrive within PHP? Are there any other warnings/errors along with the 401?
401 with the GDrive API means that you are providing invalid credentials. You must not be supplying the right auth within PHP, or at least not the same auth as you did with JS.
Thank you everyone for your help. This topic help me a lot :
Newbie Google Drive API (PHP) confusion - what guide/library to use?
The problem was indeed auth in PHP, or better, the lack of it.
Related
I'm trying to open a connexion to an IBM Cognos TM1 server through NodeJS/Axios and to do so I need to pass, during the first REST API Call everything which is needed to authenticate :
an username and password which I have
certificate information as SSL is set to true (I don't want to ignore self signed certificates)
I've found examples on how to pass certificate information with Axios but at this time I didn't succeed in getting it to work :-(
I've put in a dedicated folder, the whole ssl folder a TM1 client software is using:
E:\Development\nodejs\tm1query\assets\ssl\applixca.pem
E:\Development\nodejs\tm1query\assets\ssl\ibmtm1.arm
E:\Development\nodejs\tm1query\assets\ssl\ibmtm1.crl
E:\Development\nodejs\tm1query\assets\ssl\ibmtm1.kdb
E:\Development\nodejs\tm1query\assets\ssl\ibmtm1.rdb
E:\Development\nodejs\tm1query\assets\ssl\ibmtm1.sth
E:\Development\nodejs\tm1query\assets\ssl\importsslcert.exe
E:\Development\nodejs\tm1query\assets\ssl\tm1ca_v2.der
E:\Development\nodejs\tm1query\assets\ssl\tm1ca_v2.pem
E:\Development\nodejs\tm1query\assets\ssl\tm1store
E:\Development\nodejs\tm1query\assets\ssl\uninstallSSL.bat
E:\Development\nodejs\tm1query\assets\ssl\applixca.der
My problem is, which file do I need to use when creating the agent which will hold the connexion ?
Thanks in advance for helping or pointing me to information which can help me to go further in my understanding of how certificates works.
Regards,
Bob
So I've a dumb problem who is ruining my day so far.
I'm actually developing a React/Node app for fun. My goal is to manage a project from a unique dashboard.
I'm hoping to upload files to a google drive folder from this dashboard. So I worked on the thing with the help of the documentation https://developers.google.com/drive/api/v3/simple-upload
So far I can manage to upload files directly by hitting the endpoint with a POST method:
await Axios.post(`https://www.googleapis.com/upload/drive/v3/files`, file, {
headers: {
Authorization: `Bearer ${data.accessToken}`,
'Content-Type': file.type
}
});
but problem comes when I try to update the file with the PUT method.
To explain quickly:
I want each file that I upload to be uploaded to a specific folder on my drive. So I tought I'll make 2 calls, one to set the metadata on my API side:
API side
And once it's done return the data to my client side to update the endpoint with the ID (and a put as mentionned in the documentation)
Client side
So my question is how to PUT on this upload endpoint ? Where do I specify the ID ?
If anyone knows it would be a great help !!!
Have an awesome day all of you !
Google Drive API v3 uses PATCH rather than PUT. Change PUT to PATCH and things should work fine.
Reference: https://developers.google.com/drive/api/v3/reference/#Files
this is my first post so please go easy on me!
I am a beginning developer working with javascript and node.js. I am trying to make a basic request from a node js file to facebook's graph API. I have signed up for their developer service using my facebook account, and I have installed the node package for FB found here (https://www.npmjs.com/package/fb). It looks official enough.
Everything seems to be working, except I am getting a response to my GET request with a message saying my appsecret_proof is invalid.
Here is the code I am using (be advised the sensitive info is just keyboard mashing).
let https = require("https");
var FB = require('fb');
FB.options({
version: 'v2.11',
appId: 484592542348233,
appSecret: '389fa3ha3fukzf83a3r8a3f3aa3a3'
});
FB.setAccessToken('f8af89a3f98a3f89a3f87af8afnafmdasfasedfaskjefzev8zv9z390fz39fznabacbkcbalanaa3fla398fa3lfa3flka3flina3fk3anflka3fnalifn3laifnka3fnaelfafi3eifafnaifla3nfia3nfa3ifla');
console.log(FB.options());
FB.api('/me',
'GET',
{
"fields": "id,name"
},
function (res) {
if(!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
console.log(res);
console.log(res.id);
console.log(res.name);
}
);
The error I am getting reads:
{ message: 'Invalid appsecret_proof provided in the API argument',
type: 'GraphMethodException',
code: 100,
fbtrace_id: 'H3pDC0OPZdK' }
I have reset my appSecret and accessToken on the developer page and tried them immediately after resetting them. I get the same error, so I don't think that stale credentials are the issue. My
console.log(FB.options())
returns an appropriate looking object that also contains a long hash for appSecretProof as expected. I have also tried this code with a number of version numbers in the options (v2.4, v2.5, v2.11, and without any version key). Facebook's documentation on this strikes me as somewhat unclear. I think I should be using v2.5 of the SDK (which the node package is meant to mimic) and making requests to v2.11 of the graph API, but ??? In any case, that wouldn't seem to explain the issue I'm having. I get a perfectly good response that says my appSecretProof is invalid when I don't specify any version number at all.
The node package for fb should be generating this appSecretProof for me, and it looks like it is doing that. My other info and syntax all seem correct according to the package documentation. What am I missing here? Thank you all so much in advance.
looks like you have required the appsecret_proof for 2 factor authorization in the advance setting in your app.
Access tokens are portable. It's possible to take an access token generated on a client by Facebook's SDK, send it to a server and then make calls from that server on behalf of the client. An access token can also be stolen by malicious software on a person's computer or a man in the middle attack. Then that access token can be used from an entirely different system that's not the client and not your server, generating spam or stealing data.
You can prevent this by adding the appsecret_proof parameter to every API call from a server and enabling the setting to require proof on all calls. This prevents bad guys from making API calls with your access tokens from their servers. If you're using the official PHP SDK, the appsecret_proof parameter is automatically added.
Please refer the below url to generate the valid appsecret_proof,and add it to each api call
https://developers.facebook.com/docs/graph-api/securing-requests
I had to deal with the same issue while working with passport-facebook-token,
I finally released that the problem had nothing to have with the logic of my codebase or the app configuration.
I had this error just because I was adding intentionally an authorization Header to the request. so if you are using postman or some other http client just make sure that the request does not contain any authorization Header.
I was wondering if anyone knew how to send an email with an image attached to it from Parse's Sendgrid module (by this, I mean Facebook's Parse BaaS, not SendGrid's Parse API). So far, I can send out emails, but not with an image attached to it. I tried two different things. One is sending the email as Base64, but I read that is not supported by A LOT of email providers, therefore I was discouraged in using this method since compatibility is kind of an issue here (not critical though). My second approach was to try to mimic sendgrid's process of using a cid, but maybe I was doing something wrong and it did not work
var sendGridInstance = require('sendgrid');
sendGridInstance.initialize(sendGridUser, sendGridKey);
sendGridInstance.sendEmail({
to:endCustomerEmail,
from: 'test#test.com',
subject: 'Test subject',
html: 'My HTML goes here..',
replyto: 'donotreply#test.com'
The code above works whenever it is called in CloudCode, and indeed sends an email. But the cid thing does not work.
Has anyone successfully sent an email w/image using the sendgrid module with Parse? If so, could you please tell me what am I missing?
All help is much appreaciated!
Thank you!
Cheers!
This module doesn't support binary files - it calls SendGrid API with application/x-www-form-urlencoded request and you can't urlencode contents of binary file.
Take a look at https://github.com/m1gu3l/parse-sendgrid-mailer instead - it calls API with multipart/form-data request which is better suited for this case.
I am trying to implement the Oauth using Node JS for Glass Mirror API amd found this useful. In the "app.js" file, we need to provide the credentials of the project created in the Google developer console.
I have the client ID, client secret but am not able to define what should my callback URL be? What should be in the callback URL script? Logically I understand that there should be a program that accepts the token and runs the further steps.
But how to write one? kindly help.
Thanks in advance
base on the sample code from your link, the callback URL will be
// running in localhost
http://localhost/oauth2callback
// or running on your server
http://yourdomain.com/oauth2callback
when the google redirect to oauth2callback, your server code will run to redirect back to index page
grabToken(req.query.code, failure, function () {
res.redirect('/');
});