I would get branches in a GitHub repo but with an OAuth authentication.
I use octonode (but you use another dep, no problem), so i thought get repo like that:
const github = require('octonode');
const client = github.client();
const repo = client.repo('https://x-oauth-basic:490b285b8f92a63abfc381aa1f7f5c40aa2f9274#github.com/my-username/my-repo.git');
But the result is:
{ [Error: Not Found]
message: 'Not Found',
statusCode: 404,
headers:
{ server: 'GitHub.com',
date: 'Wed, 03 Oct 2018 08:37:07 GMT',
'content-type': 'application/json; charset=utf-8',
'content-length': '77',
connection: 'close',
status: '404 Not Found', ... },
body:
{ message: 'Not Found',
documentation_url: 'https://developer.github.com/v3' } }
Indeed, the goad is to get branches of the repo.
I found the solution by using the module #octokit/rest.
Related
I've followed this guide https://developer.paypal.com/docs/checkout/reference/server-integration/setup-sdk/ and this example https://github.com/paypal/Checkout-Nodejs-SDK/
Here is my code:
import paypalCheckout from '#paypal/checkout-server-sdk';
const environment = new paypalCheckout.core.SandboxEnvironment(
'ACTUAL_CLIENT_ID_FROM_PAYPAL_DASHBOARD',
'ACTUAL_CLIENT_SECRET_FROM_PAYPAL_DASHBOARD'
);
const client = new paypalCheckout.core.PayPalHttpClient(environment);
const request = new paypalCheckout.orders.OrdersCreateRequest();
request.requestBody({
intent: 'CAPTURE',
purchase_units: [
{
amount: {
currency_code: 'USD',
value: `100.00`
}
}
],
});
client.execute(request)
.then((response) => {
console.log(`${JSON.stringify(response)}`);
console.log(`${JSON.stringify(response?.result)}`);
})
.catch((executeError) => {
console.log(`${JSON.stringify(executeError)}`);
});
I get:
{
error: HttpError: {"error":"invalid_client","error_description":"Client Authentication failed"}
at IncomingMessage.<anonymous> (.../node_modules/#paypal/paypalhttp/lib/paypalhttp/http_client.js:136:22)
at IncomingMessage.emit (events.js:388:22)
at endReadableNT (internal/streams/readable.js:1336:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
statusCode: 401,
headers: {
'content-type': 'application/json',
'content-length': '77',
connection: 'close',
date: 'Tue, 29 Jun 2021 01:22:38 GMT',
'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
'paypal-debug-id': 'c2b.......c7a',
'x-paypal-token-service': 'IAAS',
'strict-transport-security': 'max-age=31536000; includeSubDomains'
},
_originalError: {
text: '{"error":"invalid_client","error_description":"Client Authentication failed"}',
statusCode: 401,
headers: [Object]
}
},
message: '{"error":"invalid_client","error_description":"Client Authentication failed"}'
}
I've searched Google and Stack Overflow but I only find similar issues about switching from sandbox to live.
My code isn't working in sandbox environment.
I've been trying to connect to Admob API from an AWS Lambda to extract some values from reports automatically from time to time. I've successfully got google-auth-library-nodejs to a layer and I am trying to use it to connect to Admob API.
I've made sure to give my Service account an Owner role and I've added the necessary GOOGLE_APPLICATION_CREDENTIALS path to the environement variables.
This is the code that I've added to my Lambda:
const {GoogleAuth} = require('google-auth-library');
exports.handler = (event, context, callback) => {
async function main() {
const auth = new GoogleAuth({
scopes: ['https://www.googleapis.com/auth/admob.report'],
});
const client = await auth.getClient();
//console.log("client", JSON.stringify(client));
const url = `https://admob.googleapis.com/v1/accounts`;
const res = await client.request({ url });
console.log("res: ", JSON.stringify(res.data));
}
main().catch(console.error);
};
When I run the code, I get the following error:
ERROR GaxiosError: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
at Gaxios._request (/opt/nodejs/node_modules/gaxios/build/src/gaxios.js:85:23)
at processTicksAndRejections (internal/process/task_queues.js:94:5)
at async JWT.requestAsync (/opt/nodejs/node_modules/google-auth-library/build/src/auth/oauth2client.js:350:18)
at async main (/var/task/index.js:97:19) {
response: {
config: {
url: 'https://admob.googleapis.com/v1/accounts',
headers: [Object],
params: [Object: null prototype] {},
paramsSerializer: [Function: paramsSerializer],
validateStatus: [Function: validateStatus],
responseType: 'json',
method: 'GET'
},
data: { error: [Object] },
headers: {
'alt-svc': 'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000',
'cache-control': 'private',
connection: 'close',
'content-encoding': 'gzip',
'content-type': 'application/json; charset=UTF-8',
date: 'Wed, 26 Feb 2020 18:41:51 GMT',
server: 'ESF',
'transfer-encoding': 'chunked',
vary: 'Origin, X-Origin, Referer',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '0'
},
status: 401,
statusText: 'Unauthorized',
request: { responseURL: 'https://admob.googleapis.com/v1/accounts' }
},
config: {
url: 'https://admob.googleapis.com/v1/accounts',
headers: {
Authorization: 'Bearer [Removed]',
'User-Agent': 'google-api-nodejs-client/5.10.1',
'x-goog-api-client': 'gl-node/12.14.1 auth/5.10.1',
Accept: 'application/json'
},
params: [Object: null prototype] {},
paramsSerializer: [Function: paramsSerializer],
validateStatus: [Function: validateStatus],
responseType: 'json',
method: 'GET'
},
code: 401,
errors: [
{
message: 'Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.',
domain: 'global',
reason: 'unauthorized'
}
]
}
I've been trying to find my mistake by searching on google, stack overflow, reading tutorials about connecting to Admob API as well as reading the library's code. I would really appreciate if someone could point me towards a solution.
The problem is you are trying to use a service account where OAuth User Credentials are required. You will need to implement the OAuth 2 Flow where the user enters their Google username and password.
AdMob: Authorization for the request
Refer to the following Google example on how to create a node.js OAuth 2 client.
https://github.com/googleapis/google-auth-library-nodejs#oauth2
I am using NodeJS SDK of watson to test Personality Insights Service but getting the following error:
> Error: { Bad Request: Invalid JSON input at line 1, column 2
> at RequestWrapper.formatError (C:\Users\...\Desktop\..\..\ibm-analyser-cloud\node_modules\ibm-cloud-sdk-core\lib\request-wrapper.js:208:21)
> at C:\Users\...\Desktop\..\..\ibm-analyser-cloud\node_modules\ibm-cloud-sdk-core\lib\request-wrapper.js:196:25
> at process._tickCallback (internal/process/next_tick.js:109:7) name: 'Bad Request', code: 400, message: 'Invalid JSON input at
> line 1, column 2', body:
> '{"code":400,"sub_code":"S00005","error":"Invalid JSON input at line
> 1, column 2"}', headers: { 'content-type': 'application/json',
> 'content-length': '81',
> 'access-control-allow-origin': '*',
> 'x-service-api-version': '4.0.2',
> 'x-service-build-number': '2020-01-20T06:02:53.029 UTC',
> 'x-content-type-options': 'nosniff',
> 'x-xss-protection': '1; mode=block',
> 'content-security-policy': 'default-src \'none\'',
> pragma: 'no-cache',
> 'cache-control': 'no-store',
> 'x-service-pi-error-code': 'S00005',
> 'content-language': 'en-US',
> 'strict-transport-security': 'max-age=31536000; includeSubDomains;',
> 'x-global-transaction-id': '833a39d917c511e8921aa5286669721c',
> 'x-dp-watson-tran-id': '833a39d917c511e8921aa5286669721c',
> 'x-edgeconnect-midmile-rtt': '289',
> 'x-edgeconnect-origin-mex-latency': '416',
> date: 'Tue, 28 Jan 2020 02:59:53 GMT',
> connection: 'close' } }
Below is the code snippet I am using :
app.get("/personality-insights", function(req, res) {
const personalityInsights = new PersonalityInsightsV3({
version: '2017-10-13',
authenticator: new IamAuthenticator({
apikey: watsonKeyPersonalityInsights,
}),
url: watsonUrlPersonalityInsights,
});
let params = {
content: "I am very happy today",
content_type: 'text/plain',
raw_scores: true,
consumption_preferences: true
};
personalityInsights.profile(params, function(error, response) {
if (error)
console.log('Error:', error);
else
console.log(JSON.stringify(response, null, 2));
}
);
});
this is a sample Node JS based snippet where I am providing the API credentials and the URL provided by the IBM cloud and making the request with a single line of input text. Everything seems correct but don't know why I am getting that error.
All the parameters were converted to lower camel case in v5. See the MIGRATION doc in the repo and the parameter details in the API reference
contentType
rawScores
consumptionPreferences
I have a Watson Tone cloud service up and running and I am trying to link it to my index.js file. However it doesn't seem to want to connect.
Code below:
const ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
const toneAnalyzer = new ToneAnalyzerV3({
version: '2017-09-21',
iam_apikey: 'omoNirDx1MUQwCdlHTQ-5Fxklx2_c0dUVAyMFIItFLty',
url: 'http://watson-row-analyser.eu-gb.cf.appdomain.cloud/#'
});
const text =
'Team, I know that times are tough! Product ' +
'sales have been disappointing for the past three ' +
'quarters. We have a competitive product, but we ' +
'need to do a better job of selling it!';
const toneParams = {
tone_input: { text: text },
content_type: 'application/json'
};
toneAnalyzer
.tone(toneParams)
.then((toneAnalysis) => {
console.log(JSON.stringify(toneAnalysis, null, 2));
})
.catch((err) => {
console.log('error:', err);
});
Current error code:
Marcs-MacBook-Pro:npm-global marcwatts$ node index1.js
error: { Not Found: Not Found
at formatError (/Users/marcwatts/Desktop/mxw817/DBTestApp/npm-global/node_modules/watson-developer-cloud/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:111:17)
at /Users/marcwatts/Desktop/mxw817/DBTestApp/npm-global/node_modules/watson-developer-cloud/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:259:19
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'Not Found',
code: 404,
message: 'Not Found',
body:
'"<!DOCTYPE html>\\n<html lang=\\"en\\">\\n<head>\\n<meta charset=\\"utf-8\\">\\n<title>Error</title>\\n</head>\\n<body>\\n<pre>Cannot POST /</pre>\\n</body>\\n</html>\\n"',
headers:
{ 'x-backside-transport': 'FAIL FAIL',
connection: 'close',
'transfer-encoding': 'chunked',
'content-security-policy': 'default-src \'none\'',
'content-type': 'text/html; charset=utf-8',
date: 'Sat, 06 Jul 2019 15:32:34 GMT',
'x-content-type-options': 'nosniff',
'x-powered-by': 'Express',
'x-global-transaction-id': 'ba9308f85d20bf12a70673ff' } }
Link to api for Watson:
https://cloud.ibm.com/apidocs/tone-analyzer?code=node
Code 404 means Not Found. A requested item or parameter does not exist. What am I missing?
I tried the API v1 and v2 of IBM Watson assistant to creat a new conversion.
But it gived me always the samr error code 401 Unauthorized: Access is denied due to invalid credentials.
i don't know what happened, thanks in advance for your answers.
{ Unauthorized: Access is denied due to invalid credentials.
at RequestWrapper.formatError (E:\Documents\Techniques\Desktop\front_back_end\version-watson\node_modules\ibm-watson\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:218:21)
at E:\Documents\Techniques\Desktop\front_back_end\version-watson\node_modules\ibm-watson\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:206:29
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'Unauthorized',
code: 401,
message: 'Access is denied due to invalid credentials.',
body: '{"code":401,"error":"Unauthorized"}',
headers:
{ 'x-backside-transport': 'FAIL FAIL',
'content-type': 'application/json',
'x-dp-transit-id': 'gateway01-1474836587',
'x-global-transaction-id': '7ecac92c5d14b5ae57e8386b',
'strict-transport-security': 'max-age=31536000;',
'x-dp-watson-tran-id': 'gateway01-1474836587',
'content-length': '37',
'x-edgeconnect-midmile-rtt': '82',
'x-edgeconnect-origin-mex-latency': '110',
date: 'Thu, 27 Jun 2019 12:25:18 GMT',
connection: 'close' } }
const AssistantV1 = require('ibm-watson/assistant/v1');
const service = new AssistantV1({
version: '2019-02-28',
iam_apikey: '{apikey}',
url: '{url}'
});
service.message({
workspace_id: '{workspace_id}',
input: {'text': 'Hello'}
})
.then(res => {
console.log(JSON.stringify(res, null, 2));
})
.catch(err => {
console.log(err)
});
I am not sur that for Version2 the session-id is correct or not. But the API v1 doesn't need the session_id, it gives the same error code too.