I am implementing Google drive v3 api in AngularJS version 1 project. I have gone through the docs and the related stuffs but still unable to implement it successfully. Sometime I get the error "Daily unauthorized limit exceeded" and sometime "File not found" against the query gapi.client.drive.files.list.
Here is my js code:enter code here
function start() {
gapi.client.init({
'apiKey': 'AIzaSyBqVx6XgBXjvbLZNP-aX8gBqi8pXZZhOxw',
'discoveryDocs': ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'],
}).then(function (res) {
console.log(res);
gapi.client.drive.files.list({
'pageSize': 10,
'q': "mimeType = 'application/vnd.google-apps.folder' and trashed = false",
'fields': "nextPageToken, files(id, name)"
}).then(function (response) {
console.log(response);
} else {
console.log('No files found.');
}
}, function (err) {
console.log(err)
});
})
};
gapi.load('client', start);
"Daily unauthorized limit exceeded" means you've sent a Drive request without an Access Token. That suggests that somehow you've bypassed the auth dialogue, or it failed.
Related
I have a ExpressJs Server with React Components. And the Server should handle Requests from Outside and one request should play a Song from the Spotify API when not currently playing.
app.post("/play", (req, res) => {
try {
// requesting to play uses query params
id = req.query.id;
currPlayingID = 0;
// get the currently playing song from the SPotify API
axios({
url: "https://api.spotify.com/v1/me/player/currently-playing",
method: "get",
headers: {
authorization: `Bearer ${access_token}`,
},
})
// set the currently Playing ID or to zero if nothing is playing
.then((response) => {
if (response.data !== null) {
currPlayingID = response.data.id;
} else {
currPlayingID = 0;
}
});
// only play the song if its not currently playing
if (id !== currPlayingID) {
// making a axios request to the Spotify API to play the Song with the ID
axios({
url: "https://api.spotify.com/v1/me/player/play/",
method: "put",
headers: {
authorization: `Bearer ${access_token}`,
},
data: {
uris: [`spotify:track:${id}`],
},
});
res.status(204);
}
} catch (error) {
res
.status(404)
.json({ message: "Couldn't get Info from Spotify API", error: error });
}
});
The Problem:
The Code works when I start the server on the device itself (so a local server on my Desktop PC), but when I start the Server on my RaspberryPI i cannot handle Requests to this endpoint /play. Yeah I updated all the IP Adresses, everywhere.
But the moer ointeresting part is using the React Client I get this error:
Failed to load resource: net::ERR_CONNECTION_REFUSED
Requesting with POSTMAN I get the following:
Mixed Content Error: The request has been blocked because it requested an insecure HTTP resource
And from a request using a python script I get on the server side:
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "AxiosError: Request failed with status code 400".] {
code: 'ERR_UNHANDLED_REJECTION'
}
I have no clue how to fix each error and if it is one fix. Basically I found out it is a Problem with rejeccting requests from outside localhost, because with cURL on my ssh terminal it works.
I'm learning express, so I m not an expert, but I'm looking at your errors. I will suggest you try asyncHandler module. It handles asynchronous requests and exceptions.
I faced a similar issue because while I'm sending the API request via
Axios, my token is null/empty/wrong, so make sure your token is correct
this is my request format
axios({
method:"POST",
url:"https://graph.facebook.com/v13.0/"+phon_no_id+"/message?access_token="+token,
data:{
messaging_product:"whatsapp",
to:from,
text:{
body:"Hi.. I'm Prasath"
}
},
headers:{
"Content-Type":"application/json"
}
});
I am trying to build a REST API for my server via CakePHP. I thought I had it working as I can receive the JSON responses via the web browser however when trying to access the same route via ReactJS, the Controllers Action is not actually firing.
Reading the CakePHP docs I really should only have to implement these lines of code to get the API working (According to the docs) and I did:
/config/routes.php
Router::scope('/', function($routes) {
$routes->setExtensions(['json']);
$routes->resources('Users');
});
Here is the API Endpoint I want to hit:
`public function signUp() {
$file = fopen("error_log.txt", "w");
$txt = "firing endpoint";
$fwrite($file, $txt);
$fclose($file);
$response = $this->response;
$responseText = [
"status" => "200",
"message" => "User added successfully"
];
$response = $response->withType("application/json")
->withStringBody(json_encode($responseText));
return $response;
}`
Here I am successfully hitting that endpoint via the browser. My log message also appears in the error_log.txt file
Here is where I'm making a request via ReactJS:
handleRequest = () => {
console.log('making request');
axios({
method: 'get',
url: 'https://157.230.176.243/users/register.json',
data: {
email: this.state.email,
password: this.state.password
}
})
.then(function(response) {
console.log('got response');
console.log(response);
})
.catch(function(error) {
console.log('got error');
console.log(error);
})
.then(function(data) {
console.log('always executed');
console.log(data);
});
}
When I make this request via ReactJS I get a XHR failed loading: OPTIONS "https://157.230.176.243/users/register.json"
Also when making this request via ReactJS my log message does not get written to error_log.txt
Ok I finally figured out what was wrong. I have my React Development server running on
157.230.176.243:3001
and my CakePHP API served on that same server,
157.230.176.243
React didn't like it that I was passing the full URL of the API to the fetch()
call. I switched my React code to
url: "/users/register.json"
and it works fine.
fetch('https://mylocalip:5000/api/token')
.then(function (response) {
console.log('response : ',response)
return response.json();
}).then (function (response) {
this.setState({
token: response.token
});
}).catch(function (error) {
console.log(error);
});
I read in issues on react native and use my ip to call local api. but still get network error. Im on latest version of react-native 0.55.4.
I think the correct uri should be http://mylocalip:5000/api/token (remove https) or https://mylocalip/api/token (remove port)
So I finally figured out that the issue was with the certificate. React native was not able to verify certificate self signed on localhost.
I keep hitting a 404 "user not found" error when trying to make a PUT request with auth0.
I'm trying to update a user and making this API call with the exact endpoint their docs told me to use.
When making the call from their docs (they have a built in test), everything works fine with the body I send and I receive a 200 success message.
When I try making the same call from my app, I keep getting a 404 user not found error.
However, when I use the same endpoint with the same user_id to GET from my app, everything works fine (proving my cliendID is configured correctly).
Why is this failing?
var updateAuthUser = function(){
var request = {
"user_metadata": {
"springboardID": 100055
}
}
var update = $http.put('https://app36591925.auth0.com/api/v2/users/auth0%7C5606b3c4b0c70b49698612fc', request);
update.then(function(response) {
console.log("update success", response);
}, function(response) {
console.log("update failure", response);
});
return update;
}
Working GET request:
var getAuthUser = function(){
$http.get('https://app36591925.auth0.com/api/v2/users/auth0|5606b3c4b0c70b49698612fc')
.then(function(response){
console.log("response", response);
var deferred = $q.defer();
deferred.resolve(response);
return deferred.promise;
});
}
The endpoint to update a user is to be called with PATCH, not PUT.
https://auth0.com/docs/api/v2#!/Users/patch_users_by_id
The correct response to return in this case would be 405 Method Not Allowed, but hapi does not yet support this. See https://github.com/hapijs/hapi/issues/1534.
I had this working perfectly before upgrading to angularfire 0.9
I want to request the user's email address from facebook. Facebook has already granted me permission to ask for this from my users. I am using the code below to login with facebook. It all works perfectly accept that it doesn't request the user's email.
FYI: I am using the Angularfire-seed codebase
loginWithFacebook: function() {
return auth.$authWithOAuthPopup("facebook", function(error, authData) { /* Your Code */ }, {
remember: "sessionOnly",
scope: "email, user_likes"
});
},
thanks in advance!
In response to Mike's answer below, i've noticed that the function does not run at all. not sure what the issue is.
var ref = new Firebase("https://<your-firebase>.firebaseio.com");
ref.$authWithOAuthPopup("facebook", function(error, authData) {
//THIS CODE NEVER RUNS
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
$authWithOAuthPopup takes options.
It is also best to execute it as per the documentation example:
$scope.authObj.$authWithOAuthPopup("facebook",{remember: "sessionOnly",scope: "email,user_friends"}).then(function(authData) {
console.log("Logged in as:", authData.uid);
}).catch(function(error) {
console.error("Authentication failed:", error);
});
I just hit this exact same problem. The AngularFire $authWithOAuthPopup does not seem to run the code in the function or request the email auth from Facebook. My temporary fix is to use authWithOAuthPopup (i.e. without the "$") as it seems as if there is a problem with the AngularFire wrapper.
Try it like this, If this doesn't work make sure that all your firebase and angularfire are updated.
var ref = new Firebase("https://<your-firebase>.firebaseio.com");
ref.authWithOAuthPopup("facebook", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});