Unable to share image content through share endpoint, image asset is uploaded through assets API but my request to share API which is copied directly from the example here https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/share-api?context=linkedin/compliance/context#share-content returns an error, invalid parameters in the request body [/Headers] see below details.
Request Headers:
{Authorization: Bearer ***
X-Restli-Protocol-Version: 2.0.0
}
Request Body
{"content":{"contentEntities":[{"entity":"urn:li:digitalmediaAsset:C5622AQEEn3mmqzCb5w"}],"title":"Great Result","landingPageUrl":"https://google.com.au","shareMediaCategory":"IMAGE"},"distribution":{"linkedInDistributionTarget":{}},"owner":"urn:li:person:zzR_UbXjsG","subject":"Great Result","text":{"text":"Great result, couldn't have gone better #realestate"}}
Scopes:
scope=r_emailaddress w_member_social w_organization_social r_basicprofile rw_company_admin rw_organization_admin
Error:
{"serviceErrorCode":100,"message":"Unpermitted fields present in REQUEST_BODY: Data Processing Exception while processing fields [/Headers]","status":403}
It looks like the error message has to do with the headers. Your request body is JSON, but you don't have a Content-Type header set, so this could be the problem:
Content-Type: application/json
Generally, you need a Content-Length header to be sent along with that, but most of the time the client you are using to send the request handles setting that one.
I'm not sure how you're making the request, but here is a fetch() example in JavaScript (make sure you put the correct auth token in the Authorization header):
const url = 'https://api.linkedin.com/v2/shares';
const requestBody = {
"content": {
"contentEntities": [
{
"entity": "urn:li:digitalmediaAsset:C5622AQEEn3mmqzCb5w"
}
],
"title": "Great Result",
"landingPageUrl": "https://google.com.au",
"shareMediaCategory": "IMAGE"
},
"distribution": {
"linkedInDistributionTarget": {}
},
"owner": "urn:li:person:zzR_UbXjsG",
"subject": "Great Result",
"text": {
"text": "Great result, couldn't have gone better #realestate"
}
};
async function makeRequest(url, requestBody) {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ***',
'X-Restli-Protocol-Version': '2.0.0'
},
body: JSON.stringify(requestBody) // body data type must match "Content-Type" header
});
return await response.json(); // parses JSON response into native JavaScript objects
}
// make the actual request
makeRequest(url, requestBody);
Related
I could not get the ugcPost of a post or comment, the urn looks like: urn:li:ugcPost:7023566176156811264,7023567581345140736
how to use this in the api rest/posts/{ugcPosts urn}
the API returns the error {
"message": "Could not find entity",
"status": 404,
"code": "NOT_FOUND"
}
I have also added the headers
{
Linkedin-Version: 202210,
X-RestLi-Protocol-Version: 2.0.0
}
but it is still returning the same error even though I have encoded the urn, example:
https://api.linkedin.com/rest/posts/urn%3Ali%3AugcPost%3A7023566176156811264?viewContext=Reader
You need to add a bearer token in the header. And viewContext=Reader params is not required as per my knowledge of the documentation. I am sharing a sample example.
var axios = require('axios');
var config = {
method: 'get',
url: 'https://api.linkedin.com/rest/posts/urn%3Ali%3AugcPost%3A7023566176156811264',
headers: {
'X-Restli-Protocol-Version': '2.0.0',
'LinkedIn-Version': '202208',
'Authorization': 'Bearer [your_bearer_token]',
}
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
You can visit this link for more information.
Hi I am trying to send notification to my app using firebase post method its working fine in postman but when I try to do post method in my app its returning 403. I tried implementing another get request its working fine so no problem with axios setup.
export const postData = function (url, payload) {
return AXIOS.post(url, payload, config);
};
let config = {
headers: {
'Content-Type': 'application/json',
"Authorization" : "key= *****myKey****"
}
};
Here is my post mehtod
let body = {
"to": "******myTokeb*******",
"notification": {
"title": "Title here",
"body": "R(body)",
"mutable_content": true,
"sound": "Tri-tone"
}
};
postData("http://fcm.googleapis.com/fcm/send",body).then((d)=>{
console.log("d",d)
}).catch((e)=>{
console.log("e",e);
});
Error
Error: Request failed with status code 403
at createError (D:\projects\fiver\Roeyat\node_modules\axios\lib\core\createError.js:16)
at settle (D:\projects\fiver\Roeyat\node_modules\axios\lib\core\settle.js:17)
at EventTarget.handleLoad (D:\projects\fiver\Roeyat\node_modules\axios\lib\adapters\xhr.js:61)
at EventTarget.dispatchEvent (D:\projects\fiver\Roeyat\node_modules\event-target-shim\dist\event-target-shim.js:818)
at EventTarget.setReadyState (D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:567)
at EventTarget.__didCompleteResponse (D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:389)
at D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:502
at RCTDeviceEventEmitter.emit (D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189)
at MessageQueue.__callFunction (D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:425)
at D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112
Use HTTPS in postData
That will work!
I have a route in Rails API '/api/pay'. My client side post request successfully hits the controller action, however nothing I send in the body: JSON.stringify('...') gets through to the back-end. Other post requests I have made work just fine with the same format.
export const payForItem = (payData) => {
return dispatch => {
dispatch(payForItemStart());
// ?userID=${data.userID}&adID=${data.adID}&price=${data.price}
const data = {userID: payData.userID, adID: payData.adID, price: payData.price}
fetch(`/api/pay`, {
method: 'POST',
header: {
'content-type': 'application/json'
},
body: JSON.stringify(data)
})
Here is what payData looks like.
Rails Api back-end params
Probably you've got typo in headers section. Should be plural headerS with s:
headers: {
"Content-Type": "application/json"
}
I am trying to make an API call to
https://www.googleapis.com/youtube/v3/subscriptions
I'm trying to make it so when a user logs in using google-accounts they will be able to see their YouTube subscription list. It is currently not working at I am not sure why.
Im getting two errors in the console:
1.
www.googleapis.com/youtube/v3/subscriptions?part=subscriberSnippet&mine=true&key=MYKEY&part=snippet&mine=true:1
GET https://www.googleapis.com/youtube/v3/subscriptions?part=subscriberSnippet&…ne=true&key=MYKEY&part=snippet&mine=true 401 (OK)
2.
Object {statusCode: 401, content: "{↵ "error": {↵ "errors": [↵ {↵ "domain": "gl…e": 401,↵ "message": "Invalid Credentials"↵ }↵}↵", headers: Object, data: Object}content: "{↵ "error": {↵ "errors": [↵ {↵ "domain": "global",↵ "reason": "authError",↵ "message": "Invalid Credentials",↵ "locationType": "header",↵ "location": "Authorization"↵ }↵ ],↵ "code": 401,↵ "message": "Invalid Credentials"↵ }↵}↵"data: Objectheaders: ObjectstatusCode: 401__proto__: Object
My code looks as followed:
//client side
Meteor.autosubscribe(function(){
var newUser = Meteor.user();
Meteor.subscribe('currentAccessToken');
});
var url = "https://www.googleapis.com/youtube/v3/subscriptions?part=subscriberSnippet&mine=true&key=key";
var options = {
'headers' : {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + "currentAccessToken",
'X-JavaScript-User-Agent': "Google APIs Explorer"
},
'params' : {
part : 'snippet',
mine : 'true',
}
};
var searchResult = HTTP.call("get", url,options,
function (error, result) {
if (!error) {
Session.set("twizzled", true);
}
console.log(result);
});
On the server side I am publishing the access token so that it can be sent with the GET request
//Server Side
Meteor.publish("currentAccessToken", function(){
return Meteor.users.find(this.userId, {fields: {'services.google.accessToken': 1}});
});
I greatly appreciate any help or documentation.
The first thing to check would be authorization scopes. You have to explicitly add YouTube scope (more than one, actually, each defining single action or a small bunch of actions). To do that, you can use Accounts global object. Just add this code anywhere on the client side (inside client folder):
Accounts.ui.config({
requestPermissions: {
google: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/youtube.upload'
]
},
requestOfflineToken: {
google: true
}
});
The next time you authorize with Google, you should see that the popup asks not only for basic information but for YouTube access. For more information about YouTube Google API scopes, see official docs.
Edit: I've fixed my original problem and have shown a metor example in my answer.
I'm getting a error 500 when trying to get the token for my PayPal API app in Meteor:
token = EJSON.stringify(Meteor.http.call "POST", "https://api.sandbox.paypal.com/v1/oauth2/token",
headers:
"Accept": "application/json"
"Accept-Language": "en_US"
auth: "user:pass"
params:
"grant_type":"client_credentials"
);
console.log("Token: "+token);
Output of this code:
Token: {"statusCode":500,"headers":{"server":"Apache-Coyote/1.1","date":"Fri, 15 Mar 2013 05:04:43 GMT","content-length":"0","connection":"close"},"data":null,"error":{}}
Obviously PayPal is returning a error 500 to me. I can't figure out what may be causing this. Of course Auth is actual data, not user:pass.
Why am I getting error 500?
Edit: Compiled Javascript
var token;
token = EJSON.stringify(Meteor.http.call("POST", "https://api.sandbox.paypal.com/v1/oauth2/token", {
headers: {
"Accept": "application/json",
"Accept-Language": "en_US"
},
auth: "user:pass",
params: {
"grant_type": "client_credentials"
}
}));
console.log("Token: " + token);
Here's an example implementation to make paypal API calls with meteor.
In the startup of your program, fetch your token. Always replace clientid and clientsecret with your own.
token = EJSON.parse(Meteor.http.post("https://api.sandbox.paypal.com/v1/oauth2/token",
headers:
"Accept": "application/json"
"Accept-Language":"en_US"
auth: "clientid:clientsecret"
params:
"grant_type":"client_credentials"
#encoding: "base64"
).content).access_token;
Now, create a payment, shown here in a Meteor.methods method (and returning a URL for the client to go to):
buySingleItem: () ->
console.log "Starting new payment, user id: "+Meteor.userId()
result = Meteor.http.post("https://api.sandbox.paypal.com/v1/payments/payment",
headers:
"Authorization":"Bearer "+token
"Content-Type": "application/json"
data:
{
"intent":"sale"
"redirect_urls":
"return_url":"http://mysite.herokuapp.com/done",
"cancel_url":"http://mysite.herokuapp.com/cancel"
"payer":
"payment_method":"paypal"
"transactions":[
{
"amount":
"total":"3.00",
"currency":"USD"
"description":"My item description."
}
]
}
)
payment = result.data
console.log "PayPal redirect: "+payment.links[1].href
return payment.links[1].href
This will create a PayPal checkout style payment, within Meteor.
I would provide sample code, but I'm not familiar with Meteor.
Basically you have 2 issues here:
in your headers, you are not passing the client id or client secret. This should look like:
Authorization: Basic clientid:clientsecret
Also, in your request, your request should look like this:
response_type=token&grant_type=client_credentials
Looks like your in json then stringifying it, so whatever way you need to get the POST request I just put up there, once you get it, you should be good.
[edit]PayPal's doc's dont have you base64 encode the client id or secret[/edit]
Then, when you need to execute the payment you can do as below. See the whole payment process here.
Meteor.methods
'executePaypalPayment': (payerId) ->
payment = PaypalPayments.findOne({ userId: #userId },
{ sort: { 'create_time': -1 } })
token = Meteor.call 'getPaypalToken'
url = 'https://api.sandbox.paypal.com/v1/payments/payment/' +
payment.id + '/execute'
res = Meteor.http.post url,
headers:
Authorization: 'Bearer ' + token.access_token
'Content-Type': 'application/json'
data:
payer_id: payerId
payment = res.data
payment['userId'] = #userId
if payment.state is 'approved'
# we insert the sucessful payment here
PaypalPayments.insert payment
return if payment.state is 'approved' then true else false