Decode Linkedin region codes - linkedin

I've gathered json via Linkedin API.
Node:
[GetCompanyPageStatistics][followStatistics][regions]
stores information about followers localizations, for example:
"regions": {
"_total": 9,
"values": [
{
"entryKey": "pl-8172",
"entryValue": "18"
},
{
"entryKey": "pl-8355",
"entryValue": "2"
},
{
"entryKey": "pl-8218",
"entryValue": "1"
},
{
"entryKey": "de-4944",
"entryValue": "1"
}
]
}
Given values consit of country code and region code. Is there a way to decode the region? Linkedin API documentation isn't very helpful:
https://developer.linkedin.com/docs/reference/geography-codes
(there's only eu.pl for Poland without any information about region-specific codes)

Looks like there's a v2 api to get that data:
https://learn.microsoft.com/en-us/linkedin/shared/references/v2/standardized-data/locations/regions
E.g., hitting https://api.linkedin.com/v2/regions/8172?oauth2_access_token=XXX gets you:
{
"country": "urn:li:country:pl",
"name": {
"locale": {
"country": "US",
"language": "en"
},
"value": "Warsaw, Masovian District, Poland"
},
"id": 8172,
"$URN": "urn:li:region:8172",
"states": []
}

Related

How to filter data ignoring the data that does not match

I have this query:
query ListFreightDriverTrucks($state: String! $tons: Float!) {
listFreightDrivers(filter: {
state: {
contains: $state
}
}) {
items {
name
city
state
trucks (filter: {
tons: {
eq: $tons
}
}) {
items {
id
brand
model
fuelType
fuelEfficiency
utilityPercentage
tons
axes
frontPhoto
truckBox {
type
width
height
depth
}
}
}
}
}
}
And I get as a response the data that match with the $state which is Jalisco.
{
"data": {
"listFreightDrivers": {
"items": [
{
"name": "Jaen Carlos",
"city": "Zapopan",
"state": "Jalisco",
"trucks": {
"items": []
}
},
{
"name": "Diey",
"city": "Zapopan",
"state": "Jalisco",
"trucks": {
"items": []
}
},
{
"name": "Roberto mendez",
"city": "Guadalajara",
"state": "Jalisco",
"trucks": {
"items": []
}
},
{
"name": "Engineering",
"city": "Zapopan",
"state": "Jalisco",
"trucks": {
"items": []
}
},
{
"name": "Roberto mendez",
"city": "Guadalajara",
"state": "Jalisco",
"trucks": {
"items": []
}
},
{
"name": "Andrés",
"city": "Zapopan",
"state": "Jalisco",
"trucks": {
"items": [
{
"id": "2b0cb78e-49c4-4229-8a71-60b350a5fc47",
"brand": "chevrolet",
"model": "xx",
"fuelType": "magna",
"fuelEfficiency": 12,
"utilityPercentage": 10,
"tons": 15,
"axes": 12,
"frontPhoto": "freight-driver/e9adf7fb-09c2-477e-9152-56fe4a71a96b/trucks/dlb0275xqna51.png",
"truckBox": {
"type": "Plataforma",
"width": 4,
"height": 4,
"depth": 4
}
}
]
}
}
]
}
}
}
If you check the response, there are some with this:
"trucks": {
"items": []
}
But I'm not interested in those because do not match with the $tons just the last one did. How can I remove them?
In case I need to make a lambda how the DynamoDB queries will look?
I see this question a lot which makes me a bit insecure but GraphQL isn't really supposed to work that way. You are supposed to get what you ask for and not to "SQL query yourself to victory".
Anyhoot,
You could fix this in your resolvers (the req.vtl file) by filtering out all trucks.items.length < 1 or other things. Please see this link
Appsync & GraphQL: how to filter a list by nested value
Be aware that this is a DynamoDB scan operation (all list operations are) which is quite slow.
AWS DynamoDB has the same design philosophy that you most of the time know the unique keys you are looking for and only filter over a small amount of items. Adding lots of indexes or combining keys.
Recommended reading if you want to update your data model:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices.html
Maybe rethink your GraphQL design? I don't know anything about trucks but maybe
"Location has Truck has Driver" instead?
or
"Location has Driver has Truck"?
or even both! Since GraphQL gives you what you want a Driver can contain a Truck and a Truck a Driver.
Location {
id: ID!
truck: [Truck]
driver: [Driver]
}
Truck {
id: ID!
driver: Driver!
}
Driver {
id: ID!
Truck: Truck!
}
Amplify auto generates with depth 2 so that your lists don't circle forever and you can just don't ask for what you don't need. There are tons of options here.
https://docs.amplify.aws/cli/graphql-transformer/dataaccess
If you want to make it a Lambda (#function) the dynamo syntax is quite easy (and pretty much the same).
Either you scan the whole table https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#scan-property
or you create an index which you query and then filter https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#query-property
Last but not least

What does the PROXIMITY parameter describe (Incident API)

What exactly does the PROXIMITY parameter describe, and why do ORIGIN and TO always have the same PROXIMITY?
Please see the below json snippet taken from the HERE Incident API for an example -
EDIT:
My question is not specific to the json example below but a more general question regarding the meaning of the PROXIMITY parameter.
For instance, "midway between" is pretty self explanatory. What does it mean for a traffic incident to be "at" two points or "past" two points?
In addition, for all the data I have looked at ORIGIN:PROXIMITY:DESCRIPTION is always the same as TO:PROXIMITY:DESCRIPTION. Why?
{
"INTERSECTION": {
"ORIGIN": {
"ID": "",
"STREET1": {
"ADDRESS1": "Pletschenau"
},
"STREET2": {
"ADDRESS1": "Schillerweg"
},
"COUNTY": "Calw",
"STATE": "",
"PROXIMITY": {
"ID": "MID",
"DESCRIPTION": "midway between"
}
},
"TO": {
"ID": "",
"STREET1": {
"ADDRESS1": "Pletschenau"
},
"STREET2": {
"ADDRESS1": "Birkenweg"
},
"COUNTY": "Calw",
"STATE": "",
"PROXIMITY": {
"ID": "MID",
"DESCRIPTION": "midway between"
}
}
},
"GEOLOC": {
"ORIGIN": {
"LATITUDE": 48.73873,
"LONGITUDE": 8.73767
},
"TO": [{
"LATITUDE": 48.74108,
"LONGITUDE": 8.73581
}]
}
}
```
We expecting that your use case does match with the example as follows https://developer.here.com/documentation/examples/rest/traffic/traffic-incidents-via-proximity
This example retrieves traffic incident information related to a specific area of Berlin, as defined by a radius of 15km around a specific point (the prox parameter)
The start(origin) and to(destination) both represents same waypoint here. this explains why these two are not different. In case your API call is different, please share the rest API call.

Mismatch of location id between Geocoding Autocomplete and Geocoding

I am using geocoding autocomplete to display found locations after user typed something. Afterwards I am using geocoding with given location ID to fetch detailed information about selected location.
It worked well, till I tried to select "Russia"
Here is my first request to geocoding autocomplete via https://autocomplete.geocoder.api.here.com/6.2/suggest.json
{
"app_id": "xxx",
"app_code": "xxx",
"query": "russia",
"resultType": "areas"
}
And here is the (simplified) response:
{
"suggestions": [
{
"label": "Russia",
"language": "en",
"countryCode": "RUS",
"locationId": "NT_Ya5FK7rlnK5m6PEDf7BwfA",
"address": {
"country": "Russia"
},
"matchLevel": "country"
},
...
]
}
The second request that I send to geocoding via https://geocoder.api.here.com/6.2/geocode.json with following arguments
{
"app_id": "xxx",
"app_code": "xxx",
"locationId": "NT_Ya5FK7rlnK5m6PEDf7BwfA",
"jsonattributes": "1",
"gen": "9",
"language": "en"
}
As you can see - location id is the same as in response to the first query. I suggest to become details to country russia, but instead, I receive empty response:
{
"response": {
"metaInfo": {
"timestamp": "2019-08-20T21:02:54.652+0000"
},
"view": []
}
}
After some troubleshooting I noticed, that geocoding also works with simple form input. I directly tried this request on the example page. In searchtext I type "russia", and voila, I got response (simplified):
{
"Response": {
"MetaInfo": {
"Timestamp": "2019-08-21T12:36:07.874+0000"
},
"View": [
{
"_type": "SearchResultsViewType",
"ViewId": 0,
"Result": [
{
...
"Location": {
"LocationId": "NT_tcqMSofTaW297lvniHjdXD",
"LocationType": "area",
"Address": {
"Label": "Россия",
"Country": "RUS",
"AdditionalData": [
{
"value": "Россия",
"key": "CountryName"
}
]
},
...
}
}
]
}
]
}
}
But wait, what? The ID form autocomplete was NT_Ya5FK7rlnK5m6PEDf7BwfA and from geocoding is NT_tcqMSofTaW297lvniHjdXD
Why do I receive wrong location ID from geocoding autocomplete?
We just implemented HERE API in our product, and we are testing it currently with real use-case input, and so we found this bug.
Is it just one location, that has inconsistent locationId reference, or are there some more? How can we workaround this error? Is it common?
Geocoder generates LocationId from a set of values, which uniquely identify the object. This set includes different types of data such as result type, base names and attribution of admin hierarchy, street name, house number, etc. From all this information Geocoder generates a hash value which is expected to be unique.
Using only base names guarantees that LocationId does not change if e.g. additional language variants are added to country or state name. But if the main official country or state name changes, all the areas and addresses within this country or state will get new LocationId. So using LocationId from Geocoder Autocomplete API will not always work with Geocoder API,
We will update our documentation to reflect this as the current documentation may be a bit misleading.

Linkedin API v2: Receive vanityname on signup linkedin

I'm doing the sign up integration with LinkedIn for a personal application and i have a big trouble.
We need the vanityName in order to make people visible via linkedin.
How we can redirect them to profiles without using vanityName? I tried with ID unsuccessfully.
I use this endpoint with r_liteprofile scope:
https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,vanityName,profilePicture(displayImage~:playableStreams))
and it returns me:
{
"firstName": {
"localized": {
"es_ES": "XXX"
},
"preferredLocale": {
"country": "ES",
"language": "es"
}
},
"lastName": {
"localized": {
"es_ES": "XXX"
},
"preferredLocale": {
"country": "ES",
"language": "es"
}
},
"profilePicture": {
"displayImage": "XXX",
"displayImage~": {
"elements": [...]
}
},
"id": "AX-Wv6r0Ku"
}
You can use the me endpoint of the Profile API in order to Retrieve Current Member's Profile. As example:
https://api.linkedin.com/v2/me?oauth2_access_token=<user_access_token>
With the result:
{
"firstName":{
"localized":{
"en_US":"Bob"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedFirstName": "Bob",
"headline":{
"localized":{
"en_US":"API Enthusiast at LinkedIn"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedHeadline": "API Enthusiast at LinkedIn",
"vanityName": "bsmith",
"id":"yrZCpj2Z12",
"lastName":{
"localized":{
"en_US":"Smith"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedLastName": "Smith",
"profilePicture": {
"displayImage": "urn:li:digitalmediaAsset:C4D00AAAAbBCDEFGhiJ"
}
}
If you want to retrieve only the vanityName field you can use the Field Projections as follow:
https://api.linkedin.com/v2/me?projection=(vanityName)&oauth2_access_token
With the result:
{
"vanityName": "bsmith"
}
Hope this help

Which firstname field is always returned in request to Linkedin V2 API?

When I request user details from LinkedIn’s V2 People endpoint I get the below:
Which first name and last name attribute can I use to save the user details? Is localizedLastName always returned?
{
"localizedLastName": "abc",
"lastName": {
"localized": {
"en_US": "abc"
},
"preferredLocale": {
"country": "US",
"language": "en"
}
},
"firstName": {
"localized": {
"en_US": "abc"
},
"preferredLocale": {
"country": "US",
"language": "en"
}
},
"profilePicture": {
"displayImage": "urn:li:digitalmediaAsset:C5103AQGrCbjMGgxnzQ"
},
"id": "226262627",
"localizedFirstName": "abc"
}
Hi Use this to receive the first name and last name
$profile['firstName']=array_pop($array['firstName']['localized']);
$profile['lastName']=array_pop($array['lastName']['localized']);

Resources