Retrieving the profile image from LinkedIn API response - linkedin

I've gone through the authentication and am receiving the correct data from LinkedIn and receiving a response as shown in this link:
https://developer.linkedin.com/docs/ref/v2/profile/profile-picture
However, I'm unsure how to extract the image from this:
"displayImage": "urn:li:digitalmediaAsset:C4D03AQGsitRwG8U8ZQ",
Do I need to make another request for the image url next?

For anyone else looking, I overlooked there is an identifier field like so with a url:
"identifiers": [
{
"identifier": "https://media.licdn.com/dms/image/C4D03AQGsitRwG8U8ZQ/profile-displayphoto-shrink_100_100/0?e=1526940000&v=alpha&t=12345",
"file": "urn:li:digitalmediaFile: (urn:li:digitalmediaAsset:C4D03AQGsitRwG8U8ZQ,urn:li:digitalmediaMediaArtifactClass:profile-displayphoto-shrink_100_100,0)",
"index": 0,
"mediaType": "image/jpeg",
"identifierExpiresInSeconds": 1526940000
}
To get the above response in ruby I'm doing the following:
url = 'https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))'
res = RestClient.get(url, Authorization: "Bearer #{access_token}")

Use this:
url = 'https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,emailAddress,profilePicture(displayImage~:playableStreams))&oauth2_access_token=' + access_token

Related

LinkedIn UGC Posts API with projection returns invalid paging URL

I would like to retrieve UGC posts from organization's profile using the ugcPosts API. I would also like to receive links to video streams with the response, so I use the following projection (based on this answer):
(paging,elements*(id,created,specificContent(com.linkedin.ugc.ShareContent(shareMediaCategory,shareCommentary,media(*(media~:playableStreams,originalUrl,description,title,thumbnails))))))
My whole request looks like this (retrieving the posts of the official test organization):
curl --request GET \
--url 'https://api.linkedin.com/v2/ugcPosts?q=authors&sortBy=LAST_MODIFIED&projection=(paging%2Celements*(id%2Ccreated%2ClastModified%2Cauthor%2CspecificContent(com.linkedin.ugc.ShareContent(shareMediaCategory%2CshareCommentary%2Cmedia(*(media~%3AplayableStreams%2CoriginalUrl%2Cdescription%2Ctitle%2Cthumbnails))))))&authors=List(urn%3Ali%3Aorganization%3A2414183)' \
--header 'Authorization: Bearer <ACCESS_TOKEN>' \
--header 'X-Restli-Protocol-Version: 2.0.0'
The request works as fine. But I run into an issue if I want to follow to the next page using the provided URL in paging; this is the relevant response:
{
"paging": {
"total": 284243,
"count": 10,
"start": 0,
"links": [
{
"rel": "next",
"type": "application/json",
"href": "/v2/ugcPosts?q=authors&start=10&count=10&sortBy=LAST_MODIFIED&projection=%28paging%2Celements*%28id%2Ccreated%2ClastModified%2Cauthor%2CspecificContent%28com.linkedin.ugc.ShareContent%28shareMediaCategory%2CshareCommentary%2Cmedia%28*%28media~%3AplayableStreams%2CoriginalUrl%2Cdescription%2Ctitle%2Cthumbnails%29%29%29%29%29%29&authors=List(urn%3Ali%3Aorganization%3A2414183)"
}
]
}
}
On the first page, you can see that parentheses in the projection parameter got URL encoded, while authors parameter remains the same. This request still works, but if I follow the URL one more time, I recieve the following paging data:
{
"paging": {
"total": 284243,
"count": 10,
"start": 10,
"links": [
{
"rel": "prev",
"type": "application/json",
"href": "/v2/ugcPosts?q=authors&start=0&count=10&sortBy=LAST_MODIFIED&projection=%2528paging%252Celements*%2528id%252Ccreated%252ClastModified%252Cauthor%252CspecificContent%2528com.linkedin.ugc.ShareContent%2528shareMediaCategory%252CshareCommentary%252Cmedia%2528*%2528media~%253AplayableStreams%252CoriginalUrl%252Cdescription%252Ctitle%252Cthumbnails%2529%2529%2529%2529%2529%2529&authors=List(urn%3Ali%3Aorganization%3A2414183)"
},
{
"rel": "next",
"type": "application/json",
"href": "/v2/ugcPosts?q=authors&start=20&count=10&sortBy=LAST_MODIFIED&projection=%2528paging%252Celements*%2528id%252Ccreated%252ClastModified%252Cauthor%252CspecificContent%2528com.linkedin.ugc.ShareContent%2528shareMediaCategory%252CshareCommentary%252Cmedia%2528*%2528media~%253AplayableStreams%252CoriginalUrl%252Cdescription%252Ctitle%252Cthumbnails%2529%2529%2529%2529%2529%2529&authors=List(urn%3Ali%3Aorganization%3A2414183)"
}
]
}
}
You can see here that the projection parameter got URL-encoded again (having %252C for parens) and following that URL returns error 400.
I think this is a bug in the API, but since LinkedIn recommends to use Stack Overflow for support, I just wrote this up here, hopeful someone notices. Perhaps could you suggest another way of contacting LinkedIn about this bug in their API?
Meanwhile I resorted to constructing the pagination URL manually.

Fetch company posts from linkedin API

I am trying to fetch the posts of the company from the api, I have already applied to the marketing development platform and it was approved. I already got the token with the scope: r_organization_social and I'm calling the /shares api:
https://api.linkedin.com/v2/shares?q=owners&owners=urn:li:organization:{company_ID}&sharesPerOwner=100&count=25&sharesPerOwner=10
But I'm getting the following response:
{
"paging": {
"start": 0,
"count": 25,
"links": [
{
"type": "application/json",
"rel": "next",
"href": "/v2/shares?count=25&owners=urn%3Ali%3Aorganization%3A{company_ID}&q=owners&sharesPerOwner=10&sharesPerOwner=100&start=0"
}
],
"total": 242
},
"elements": []
}
I tried to change the query params and it's still the same
This end-point worked for me:
https://api.linkedin.com/v2/ugcPosts?q=authors&authors=List(urn%3Ali%3Aorganization%3A<ID_ORGANIZATION>)
See documentation: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/ugc-post-api?tabs=http#sample-request-6
Disclaimer: I've no access to the linkedin API and couldn't test. But these are some things I noticed:
Your url contains two times the paramater sharesPerOwner, try removing one.
In the docs it's recommended to set the sharesPerOwner to 1000 and the count to 50. I'd also include the start paramater, just to make sure:
Maybe try something like this:
GET https://api.linkedin.com/v2/shares?q=owners&owners=urn:li:organization:{id}&sharesPerOwner=1000&count=50&start=0
From the api-docs(https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/share-api?tabs=http#find-shares-by-owner): "Note that the pagination excludes UGC and Direct Sponsored Content (DSC) posts". Make sure that the owner you are testing contains posts.
If this doesn't work. Could you provide some information on how you are sending the request? Have you tried accessing other parts of the api?

Find and delete Discord webhook message

I'm using a Discord webhook to send information which may later be invalidated, so I want to be able to delete it. To do this i use these endpoints:
First i make a post request to send a message:
POST /webhooks/{webhook.id}/{webhook.token}
And then i want to do a delete request to remove the message again:
DELETE /webhooks/{webhook.id}/{webhook.token}/messages/{message.id}
However I don't have the ID of the message i want to delete, since no response is given to the first POST request which is always an empty 204 response. Is it possible to get the message id?
Any help would be appreciated.
Per this reddit post:
If you need to reference a message ID of a webhook message you sent, you can add ?wait=true to the end of the URL which will give you the message data (including the ID) instead of a 204 (No Content) when you don't include the query parameter.
So if you send your normal POST request to your url like this: POST /webhooks/{webhook.id}/{webhook.token}, add ?wait=true to the end of that. Then you will get back data like this:
{
"id": "MESSAGEID",
"type": 0,
"content": "This is a test",
"channel_id": "CHANNELID",
"author": {
"bot": true,
"id": "AUTHORID",
"username": "USERNAME",
"avatar": "AVATARID",
"discriminator": "0000"
},
"attachments": [],
"embeds": [],
"mentions": [],
"mention_roles": [],
"pinned": false,
"mention_everyone": false,
"tts": false,
"timestamp": "2021-11-13T18:10:24.412000+00:00",
"edited_timestamp": null,
"flags": 0,
"components": [],
"webhook_id": "WEBHOOKID"
}

Google Calendar API - Create & Share via email

All the old questions are 3-8 years out of date. Need help with V3 of Google calendar API.
I don't get how to specifically invite an email to the calendar from this documentation: https://developers.google.com/calendar/v3/reference/acl
I see how to set the share permissions of the selected calendar, but where do we put the email that we want to share to??
so i guess that you want to share your calendar with an email, this is my working code in python:
#ACL INSERT add partecipant to a calendar
def update_calendar_by_adding_partecipant_to_a_calendar():
id = "mail#gmail.com"
url = "https://www.googleapis.com/calendar/v3/calendars/"+ id +"/acl"
payload = {
"role": "reader",
"scope": [{
"type": "user",
"value": "mail#gmail.com"
}]
}
response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
json_response = response.text
json_share=json.loads(json_response)
print(json_share)

400 bad request when trying to submit a POST request

I'm applying to a job and the way they ask their applicants to send in a resume is through api. The directions ask:
Submit a POST request to our careers endpoint with a raw JSON request body:
Here is the json:
POST https://contact.website.com/jobs
{
"name": "Jane Applicant",
"email": "jane#hotmail.com",
"resume": "www.linktoresume.io",
"github": "github.com/jane",
"twitter": "#jane",
"website": "jane.com"
}
I used postman and chose post as the request then put in the correct url. I created keys and values for all of the fields they expected but I get a 404 bad request when I try to submit. Not sure what I'm doing wrong.
Ensure you've set the POST request format to JSON:
Comments aren't allowed in JSON so the body should just be
{
"name": "Jane Applicant",
"email": "jane#hotmail.com",
"resume": "www.linktoresume.io",
"github": "github.com/jane",
"twitter": "#jane",
"website": "jane.com"
}

Resources