call facebook v3.0 translation but got NNN does not exist, cannot be loaded due to missing permissions, - node.js

try to Invoke Facebook v3.0 translations service but got exception like this "
Unhandled rejection StatusCodeError: 400 - "Unsupported post request. Object with ID 'XXXXXX
XXXXXX' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation ,
and with "type":"GraphMethodException","code":100, "error_subcode":33,
here is my node-js code
const request = require('request-promise');
var uri = 'https://graph.facebook.com/v3.0/my_app_id/translations?'
+ 'access_token=my_app_token';
const options = {
method: 'POST',
uri: uri,
qs: {
native_strings: [{"text":"Test String", "description": "This is a test string."}]
}
};
request(options).then(function (res1) {
console.log(res1);
res.write('request done : ' + res1);
res.end();
}
the app token can be obtained via facebook tool explorer
what am I doing wrong?

Related

How to request data with token authorization in custom functions in Office JS Excel-Add-In?

What I have:
I adapted this example from Microsoft docs.
// functions.js
/**
* Get data
* #customfunction
* #returns {string[][]}
*/
async function getData() {
try {
const url = "https://api.example.com/some/objects/";
const token = await OfficeRuntime.storage.getItem("Token");
const authString = `Token ${token.toString()}`;
const response = await fetch(url, {
headers: { Authorization: authString }
});
if (!response.ok) {
throw new Error(response.statusText);
}
const jsonResponse = await response.json();
return jsonResponse.map(obj => {return [obj.id.toString(), obj.name]};
} catch (error) {
return [["ERROR", error.message]];
}
}
Added api.example.com to <AppDomains>
Item "Token" is present in OfficeRuntime.storage
Same API call with Postman works fine
The Add-In is not served from localhost (because of CORS reasons etc.)
What I get:
Because it is not developed locally it is very hard to debug ui-less custom functions. Therefore the only visible error I get so far, is the one I receive and return to Excel in the catch-block. It is an unhelpful error message: Network request failed
Can anyone help me with any suggestions?
Reason why it did not work was a known issue that custom functions run in a separate JavaScript runtime as described here. This runtime allows only CORS-safelisted request header because it lacks of CORS-Preflight -> therefore the Network request failed error with the Authorization header.
How I solved it:
Configure the Excel-Add-in to use a shared JavaScript runtime as described here.
Add <script src="functions.js"></script> just before the <\head> element in taskpane.html as described here.
Build the project npm run build
Clear the cache as described in the first two steps here.
Run Excel and load your Add-in.

Cannot get the headers after I set the mapping template in API GATEWAY

I would like to call an api with a header and body for admin user delete a user data like this:
apiClient.post('***endpoint***',
{ tableName: '***',
id: id },
{
headers: {
Authorization: accessToken
}
})
and I want to show the detail in lambda first before I write any function to access my db:
var AWS = require('aws-sdk')
AWS.config.update({ region: '***' })
var ddb = new AWS.DynamoDB()
exports.handler = async function (event , ctx , callback) {
return event
};
and in APIGATEWAY, I set the following
{
"Authorization" : "$input.params('Authorization'),
"body" : $input.json('$')
}
with content-type isapplication/json in Integration Request
Then when I test the api in Method Test .
In Header , I type "testaccesstoken",
In body , I type { "id":"1", "tableName":"test"},
But the result is{
"Authorization": "",
"body": {
"id": "1",
"tableName": "test"
}
}
Can anyone explain to me why I still cannot get the header?
Also when I test in poseman,I try like this:,
and I get an error
I hv already deployed the API but why I cannot test in postman??
In your Postman, set your header is Authorization instead of "Authorization"
I noticed you mentioned the mapping template and passthrough behavior but nothing about mapping it in your Method Request or the header field in Integration Request in API Gateway. There is a recent answer here I think may give you some things to verify are set correctly, as I suspect that may be the issue.
It also covers using a proxy integration instead, let me know if there is a more specific issue in the comments and I'll adjust my answer if needed!

getting 403 error while sending file to githib via REST using nodejs

I want to send multiple files to Github repository via nodejs. Tried several approaches and end up using node-rest-client module. Tried below code send a sample file to repository called 'metadata'. But after post I am getting error message "Request forbidden by administrative rules. Please make sure your request has a User-Agent header"...please let me know if anyone faced this error before and get rid of it.
convertval = "somedata";
var dataObj = {
"message": "my commit message",
"committer": {
"name": "Scott Chacon",
"email": "ravindra.devagiri#gmail.com"
},
"content": "bXkgbmV3IGZpbGUgY29udGVudHM="
}
debugger;
var Client = require('node-rest-client').Client;
var client = new Client()
var args = {
data: dataObj,
headers: { 'Content-Type': 'application/json' },
};
client.post("https://api.github.com/repos/metadata/contents", args, function (data, response) {
console.log("file send: True : " + data);
});
According to the REST API:
All API requests MUST include a valid User-Agent header. Requests with
no User-Agent header will be rejected.
First of all, you need to define 'User-Agent' with value 'request' in your request header. Refer to this link.
Second, endpoint you are trying to call might require authentication. Generate a personal token from here, add that token in your request header, 'Authorization': 'token '.
If you're using Git extensively in your code, I suggest you to use this - Nodegit.
Edit:
I don't think sending multiple files in a single request is possible in 'Contents' endpoints group (link).
You can checkout Git Data API (as discussed here).

How do I access the path parameter of AWS API Gateway? I always get "message": "Missing Authentication Token"

My objective is the following:
Have REST endpoint: /api/v1/{ID}
My lambda should be able to access {ID} and do logic
Right now my api gateway looks like:
/
/api
/v1
/-id-
GET
I've added a "Mapping Template":
{"id":"$input.params('id')"}
When I enter the url in browser "https...../dev/api/v1/-id-" I get:
{ id: "" }
When I enter "https....../dev/api/1234", I get:
{ "message": "Missing Authentication Token" }
I didn't set up any sort of authentication stuff for the url...
My lambda code:
console.log('Loading function');
exports.handler = function(event, context) {
var query = require('querystring').parse(event.querystring)
console.log("the query ==> ", query);
console.log('Received event:', JSON.stringify(event, null, 2));
console.log("the context ==> ", context)
context.succeed(event);
};
What am I missing that'll enable me to return the "id" when entering the url on a browser?
I also ran some java code with get requests against the url, get 403 whenever I set "-id-" to some string/number...
read the docs!!!!
http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-mappings.html
resource name: anything really
resource path: THIS NEEDS TO BE {PARAM_NAME} if you want to use the url like "/api/v1/PARAM_VALUE"

Facebook access token not accepted to Open Graph using Node.js facebook-node-sdk

Posting an Open Graph action using the Node.js facebook-node-sdk module gives me {"error": "An active access token must be used to query information about the current user."}.
var FB = require( 'fb' )
var path = '/me?' + namespace + ':' + action_type_name
var body = {
access_token: myAccessToken,
myAction : myCustomObjectURL
}
FB.api( path, 'post', body, function( res )
{
if( res.error ) {
console.log( 'the call to open graph failed: ' + res.error.message );
}
else {
console.log( 'success' )
}
})
If I print this access token and use it with cURL (curl https://graph.facebook.com/me?access_token=myAccessToken), it returns correctly, no error. Facebook also shows that the app has permission to post as this user. So what am I doing wrong here?
D'oh, stupid question. It turns out I needed a slash instead of a question mark in the URL path: path = '/me/' + ...
Actually this is a bug of the node facebook api.
When you use a '?' in your api-calls the accesstoken gets appended with another '?'
https://github.com/Thuzi/facebook-node-sdk/blob/master/fb.js#L268
This leads to a api-call like this one: https://graph.facebook.com/me/friends?limit=10?access_token=vSAEFfionhaWFwai...
You see multible '?' in the request and Facebook can not find the accesstoken anymore because of this.

Resources