I'm working on a small website that can do stuff with the Google Calendar API. I've posted it over here: http://evansiroky.com/temp-gcal-question/tests/ Whenever I try to authorize, it doesn't seem to matter what clientId I use, it always says it is authorized. Also, it doesn't seem to matter if immediate is set to true or false. Here is the authorization code:
gapi.auth.authorize({
client_id: clientId,
scope: ['https://www.googleapis.com/auth/calendar'],
immediate: immediate
}, function(authResult) {
if(authResult && !authResult.error) {
isAuthorized = true;
} else {
isAuthorized = false;
}
if(callback) {
var out = isAuthorized ? null : authResult;
callback(out);
}
});
However, once I try to list events of a calendar, I get a dailyLimitExceededUnreg error. Here is the code for listing events:
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.list(_.extend({
calendarId: 'primary',
orderBy: 'starttime',
singleEvents: true,
showDeleted: true,
}, options.data));
request.then(function(resp) {
options.success(resp);
}, function(reason) {
options.failure(reason);
});
});
And here is the error that is returned:
{
"result": {
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
},
"body": "{\n \"error\": {\n \"errors\": [\n {\n \"domain\": \"usageLimits\",\n \"reason\": \"dailyLimitExceededUnreg\",\n \"message\": \"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.\",\n \"extendedHelp\": \"https://code.google.com/apis/console\"\n }\n ],\n \"code\": 403,\n \"message\": \"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.\"\n }\n}\n",
"headers": {
"date": "Fri, 02 Oct 2015 19:08:41 GMT",
"content-encoding": "gzip",
"server": "GSE",
"vary": "Origin, X-Origin",
"content-type": "application/json; charset=UTF-8",
"cache-control": "private, max-age=0",
"content-length": "215",
"expires": "Fri, 02 Oct 2015 19:08:41 GMT"
},
"status": 403,
"statusText": "OK"
}
What am I doing wrong?
Related
I am trying to use the Citi Bank Open API in my React Native mobile app. I was able to call the API to let user sign in with their Citi Bank account and get the client authorization code. However, when I was trying to call another API for validating the code I got, it returned a weird error without any description.
I suspect problems may be caused by:
my app is still in development stage
I didn't do the calling on the redirect uri, but the domain is definitely the same
The API is supposed to return an access token for further interaction, but all I got is the error. I wanna know what might be the possible mistakes.
This is my first time trying to use an open API inside my app. Any suggestion will be much appreciated.
Official docs from Citi (may need to register an account):
https://sandbox.developerhub.citi.com/api/hong-kong/retail-bank/identity-security/authorize/documentation
Calling the API:
fetch(
"https://sandbox.apihub.citi.com/gcb/api/authCode/oauth2/token/hk/gcb",
{
method: "POST",
body: new URLSearchParams({
grant_type: "authorization_code",
code: auth_code,//got from the response of GET /authCode/oauth2/authorize
redirect_uri: "http://localhost:19000/redirect",
}),
headers: new Headers({
"Cross-Domain": true,
Accept: "application/json",
Authorization:
"Basic " + btoa(CITI_CLIENT_ID + ":" + CITI_CLIENT_SEC),
"Content-Type": "application/x-www-form-urlencoded",
}),
}
)
.then((data) => {
console.log(data);
data.json();
})
.then((result) => {
console.log(result);//undefined
});
Response:
Response {
"_bodyBlob": Blob {
"_data": Object {
"__collector": null,
"blobId": "f09ce99b-1a3b-4251-9a73-5a4a809a6296",
"offset": 0,
"size": 88,
},
},
"_bodyInit": Blob {
"_data": Object {
"__collector": null,
"blobId": "f09ce99b-1a3b-4251-9a73-5a4a809a6296",
"offset": 0,
"size": 88,
},
},
"bodyUsed": false,
"headers": Headers {
"map": Object {
"access-control-allow-credentials": "true",
"access-control-allow-headers": "",
"access-control-allow-methods": "",
"access-control-allow-origin": "",
"access-control-expose-headers": "",
"connection": "close",
"content-length": "88",
"content-type": "application/json",
"date": "Thu, 24 Mar 2022 06:37:39 GMT",
"set-cookie": "CITI_SITE=gtdc; expires=Thu, 24-Mar-2022 06:57:39 GMT; path=/; domain=sandbox.apihub.citi.com; secure; HttpOnly",
"x-akamai-citisite": "GTDC",
"x-backside-transport": "FAIL FAIL,FAIL FAIL",
"x-global-transaction-id": "6e68aa42623c11b387504e5d",
},
},
"ok": false,
"status": 400,
"statusText": "",
"type": "default",
"url": "https://sandbox.apihub.citi.com/gcb/api/authCode/oauth2/token/hk/gcb",
}
I have a cypress spec with which I want to test a function on my site which polls a third party API until it receives a correct answer and then shows more information for the user to continue with the function.
I start my spec with
cy.server();
cy.route('GET', '**/that-other-api/**').as('otherApi');
I know that this part works. The route is listed in the top of the Cypress test GUI, and my otherApi alias is attached to the XHR requests when they are listed in the command list when running.
When the user (or my test) clicks a button the site will start polling that endpoint. When I receive a status: success in the response, the user (or my test) is provided with a filled dropdown of options and can continue.
How can I get Cypress to wait until I get that specific response from the XHR request (or reaches a cypress timeout) and then continue onwards?
The Network request documentation doesn't explain if this is possible or not. I have tried
cy.wait('#billectaAccounts').should('have.property', 'response.body.status', 'success');
and just to see if stuff works
cy.wait('#billectaAccounts').should('have.property', 'status', 201);
which both throw an error:
InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'json').
Logging the response with
cy.wait('#billectaAccounts').then(console.log);
logs the response and shows that my status variable is there, but is pending since it's only on the first request.
{
"xhr": {
"method": "GET",
"url": "https://myapi/longToken",
"id": "xhr193"
},
"id": "xhr193",
"url": "https://myapi/longToken",
"method": "GET",
"status": 200,
"statusMessage": "200 (OK)",
"request": {
"headers": {
"Accept": "application/json, text/plain, */*"
},
"body": null
},
"response": {
"headers": {
"cache-control": "max-age=0, private, must-revalidate",
"connection": "close",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 24 Mar 2020 08:32:09 GMT",
"etag": "W/\"f0d6999f3be78c3dc8eab419745ec489\"",
"referrer-policy": "strict-origin-when-cross-origin",
"server": "Cowboy",
"vary": "Origin",
"via": "1.1 vegur",
"x-content-type-options": "nosniff",
"x-download-options": "noopen",
"x-frame-options": "SAMEORIGIN",
"x-permitted-cross-domain-policies": "none",
"x-request-id": "id",
"x-runtime": "0.006788",
"x-xss-protection": "1; mode=block"
},
"body": {
"id": 721,
"public_id": "longTokenId",
"bank": "bank-id",
"ssn": "ssn-number",
"status": "pending",
"created_at": "2020-03-24T09:32:05.362+01:00",
"updated_at": "2020-03-24T09:32:06.028+01:00",
"account_numbers": [],
"token": "pollingToken"
}
},
"duration": 230
}
I would prefer to not stub the response, It's nice to have the end to end test to that API.
Any help appreciated!
I am working with Pluralsight API and their API responds CSV files as results, which I would like to grab this data from response and print out.
this is the URL of the Pluralsight API:
https://app.pluralsight.com/plans/api/reports/docs
and this is the code I am trying to do:
request
.get('https://api.pluralsight.com/api-v0.9/users?planId=x&token=y')
.on('response', function (response) {
res.json(response);
})
The response does not show any data except for the data as below:
{
"statusCode": 200,
"headers": {
"cache-control": "private",
"content-disposition": "attachment; filename=Users.csv",
"content-type": "text/csv",
"date": "Fri, 27 May 2016 03:42:06 GMT",
"ps-build": "2016.5.1849.0",
"ps-node": "0Q5JR",
"ps-responsetime": "00:00:00.1406230",
"content-length": "11391",
"connection": "Close"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "api.pluralsight.com",
"port": 443,
"hostname": "api.pluralsight.com",
"hash": null,
"search": "?planId=x&token=y",
"query": "planId=x&token=y",
"pathname": "/api-v0.9/users",
"path": "/api-v0.9/users?planId=x&token=y",
"href": "https://api.pluralsight.com/api-v0.9/users?planId=x&token=y",
},
"method": "GET",
"headers": {}
}
}
Is there anyway that I get get the file from attachment and extract it?
Thanks
Request body is accessible through data and end events.
var body = [];
request
.get('https://api.pluralsight.com/api-v0.9/users?planId=x&token=y')
.on('data', function (chunk) {
body.push(chunk);
})
.on('end', function () {
body = body.join('');
// body now contains csv contents as a string
});
I’m making a Chrome extension for Google Calendar where I need to authenticate to a Google Cloud Endpoints server. I use the Google APIs Client Library for JavaScript for that, with the gapi.auth.authorize method:
var SCOPES = [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/calendar.readonly"
];
function login() {
gapi.client.oauth2.userinfo.get().execute(function(response) {
if (response.code) {
console.log("cannot auth: " + response.code + " (" + response.message + ")");
} else {
console.log("authed " + response.email);
}
});
}
gapi.auth.authorize({
client_id: CLIENT_ID,
scope: SCOPES.join(" "),
immediate: immediate
}, login);
Now, sometimes it works, sometimes it doesn’t. In that case, a popup appears and is closed immediately, and the response object contains:
{
"code": 401,
"message": "Invalid Credentials",
"data": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"error": {
"code": 401,
"message": "Invalid Credentials",
"data": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
]
}
}
I cannot for the life of me find out the error’s source, or why it only happens occasionally. Note that another webapp uses the exact same code (client ID included) and works flawlessly.
gapi.auth.authorize({
client_id: CLIENT_ID,
scope: SCOPES.join(" "),
immediate: true
}, login);
I am making a adapter for HTTP soap based invocation, code for invocation is given below while invoking the adapter i am getting error like :"Cannot read property "Body" from undefined" .
SOAPAdapter.xml is:
<wl:adapter xmlns:wl="http://www.worklight.com/integration" xmlns:http="http://www.worklight.com/integration/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="SOAPAdapter">
<displayName>SOAPAdapter</displayName>
<description>SOAPAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>*.*.com</domain>
<port>80</port>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2"/>
</connectivity>
<procedure name="get_soap_req_list"/>
SOAPAdapter-impl.js is:
function get_soap_req_list() {
var request =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
+'<soap:Body>'
+'<AddList xmlns="http://schemas.microsoft.com/sharepoint/soap/">'
+'<listName>tiu</listName>'
+'<description>uyt</description>'
+'<templateID>6</templateID>'
+'</AddList>'
+'</soap:Body>'
+'</soap:Envelope>';
WL.Logger.debug("###"+request);
var input = {
method : 'post',
returnedContentType : 'xml',
path : '/_vti_bin/Lists.asmx',
body : {
content: request.toString(),
contentType: 'text/xml; charset=utf-8'
}
};
**27** var result = WL.Server.invokeHttp(input);
**28** return result;
}
console error is:
E: An error occurred while invoking procedure SOAPAdapter/get_soap_req_listFWLSE0100E: parameters:{
"arr": [
9
]
}
TypeError: Cannot read property "Body" from undefined (D%3A%5CWorklightworkSpace%5Cmodule_05_2_HTTP_Adapter%5Cadapters%5CSOAPAdapter/SOAPAdapter- impl.js#42)
FWLSE0101E: Caused by: null
result OutPut:
{
"errors": [
],
"info": [
],
"isSuccessful": true,
"responseHeaders": {
"Content-Length": "0",
"Date": "Thu, 20 Jun 2013 11:08:03 GMT",
"MicrosoftSharePointTeamServices": "14.0.0.6123",
"SPRequestGuid": "7a89adce-9ede-4197-bfc4-aff18e85e763",
"Server": "Microsoft-IIS/7.5",
"WWW-Authenticate": "NTLM",
"X-MS-InvokeApp": "1; RequireReadOnly",
"X-Powered-By": "ASP.NET"
},
"responseTime": 156,
"statusCode": 401,
"statusReason": "Unauthorized",
"text": "",
"totalTime": 172,
"warnings": [
]
}
Change to "return result;"
What is the output?