Showing posts with label linkedin-api. Show all posts
Showing posts with label linkedin-api. Show all posts

Sunday, July 15, 2018

Get the URL of an ad in LinkedIn Marketing API

Leave a Comment

I am wokring in the linked in marketing api to create a tool letting use report on our ads. One thing I need is the URL of the ads to show stats per destination.

I am not entirely sure which part of the ad this is tied to, but I assumed it is tied to creative.

In the documentation it shows an example request

https://api.linkedin.com/v2/adCreativesV2/{ID} 

and it provides a result with a click URI

{     {         "campaign": "urn:li:sponsoredCampaign:326050844",         "id": 104748094,         "review": {             "reviewStatus": "PENDING"         },         "status": "ACTIVE",         "type": "TEXT_AD",         "variables": {             "clickUri": "http://www.dundermifflin.com",             "data": {                 "com.linkedin.ads.TextAdCreativeVariables": {                     "imageId": "",                     "text": "Out of paper. Out of stock. There's friendly faces around the block.",                     "title": "People Person's Paper People"                 }             }         }     } 

but when I submit a request it does not give me this information. My request (id changed for privacy of clients)

 https://api.linkedin.com/v2/adCreativesV2/12345678 

returns with

{      "reference":"urn:li:share:xxxxxxxxxxxxxxxxx",    "variables":{         "data":{            "com.linkedin.ads.SponsoredUpdateCreativeVariables":{               "activity":"urn:li:activity:xxxxxxxxxxxxxxxxx",             "share":"urn:li:share:xxxxxxxxxxxxxxxxx",             "directSponsoredContent":true          }       }    },    "changeAuditStamps":{         "created":{            "time":1499978379000       },       "lastModified":{            "time":1518332188000       }    },    "review":{         "reviewStatus":"AUTO_APPROVED"    },    "campaign":"urn:li:sponsoredCampaign:xxxxxxxxx",    "servingStatuses":[         "RUNNABLE"    ],    "id":12345678,    "type":"SPONSORED_STATUS_UPDATE",    "version":{         "versionTag":"3"    },    "status":"ACTIVE" } 

1 Answers

Answers 1

It turns out that some creatives simply do not have a clickURI.

One example of this is the LinkedIn Lead Gen Form system. Your ad forwards into a lead generation system created in LinkedIn rather than to a specified URL.

Read More

Wednesday, April 11, 2018

LinkedIn authentication stopped returning formatted picture

Leave a Comment

My app uses LinkedIn authentication along with a couple of other social network logins.

Even though authentication is working fine, all of a sudden LinkedIn stopped returning the formatted profile picture i.e. picture-url. I do however continue to receive the original image i.e. picture-urls -- see below: enter image description here

In my authentication request, I request r_basicprofile and r_emailaddress and according to this link, I should be receiving both the formatted and the original image. https://developer.linkedin.com/docs/fields/basic-profile

Up until 10 days ago or so, I was receiving both images. I didn't make any changes to my code but for some reason, the formatted image doesn't show up anymore. Any idea why and how to fix this?

UPDATE: All of a sudden I started getting both images again -- without making any changes to my code.

I also noticed that the image URL has now changed and I'm seeing all types of parameters in there -- such as image size, something that looks like API version type (alpha in the example below) and possibly a time stamp indicator:

https://media.licdn.com/dms/image/{image-id}/profile-displayphoto-shrink_100_100/0?e=123456789&v=alpha&t={sometypeofid} 

I don't remeber seeing any of these parameters in the image URL which is not a URL at all but what seems to be an API call that returns an image.

I don't know if LinkedIn announced such changes that I missed or just decided to make these changes without keeping developers in the loop. I hope it's not the latter and I simply missed the announcement.

0 Answers

Read More

Friday, September 15, 2017

Linkedin tokens expire in a day instead of 60 days

Leave a Comment

Linkedin's API documentation states that the access token granted lasts for 60 days, but in some cases I've seen it expire within a day. Once we drive the user through the authentication process to get the access token, we are able to post on their page. But when we try posting for them the next day, the API returns an error "Unable to verify access token". There are pages where I don't see this issue and I've been posting for the last couple of weeks. My issue is that I can't figure out the difference between the pages where the tokens expire in a day and where they don't. Help?

1 Answers

Answers 1

I have seen the behaviour you describe only when after an authorization the access token was not updated in our db. An authorization will invalidate the previous token and the API calls will return that message.

Edit- response to comment: Make sure the database is updated with the tokens after each user authentication, ensure that the user is not going over the authentication again in some other place in the app without saving token (or requesting different permissions) because those two cases will generate that error message.

Read More

Thursday, July 27, 2017

LinkedIn API OAuth refresh token

Leave a Comment

I am using LinkedIn API to pull updates from there and display on the website. While using OAuth, I am storing the token in a file and then pull it from there again to prevent the login popup. However, I am not clear once my token expires how will it get refreshed. Following is how I am reading the token from the file -

        $config = json_decode(file_get_contents(".service.dat"));         if( isset($config->key) && isset($config->secret) ) {             $this->access_token = new OAuthConsumer($config->key, $config->secret);         }  

For authentication I have following to get request token -

function getRequestToken() {     $consumer = $this->consumer;     $request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $this->request_token_path);     $request->set_parameter("oauth_callback", $this->oauth_callback);     $request->sign_request($this->signature_method, $consumer, NULL);     $headers = Array();     $url = $request->to_url();     $response = $this->httpRequest($url, $headers, "GET");     parse_str($response, $response_params);     $this->request_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1); } 

After generating token, I am generting authorize url:

function generateAuthorizeUrl() {     $consumer = $this->consumer;     $request_token = $this->request_token;     return $this->authorize_path . "?oauth_token=" . $request_token->key; } 

LinkedIn documentation states following about refresh token:

Refreshing an access token is very simple and can happen without an authorization dialog appearing for the user. In other words, it's a seamless process that doesn't affect your application's user experience. Simply have your application go through the authorization flow in order to fetch a new access token with an additional 60 day life span.

I am not clear what that means. If I have to redo all the way from obtaining request token again then wouldn't that require me to make http request again and having to popup the login screen? How do I avoid it? Will appreciate suggestion.

Thanks.

1 Answers

Answers 1

Found out. Authorization URL:

https://www.linkedin.com/oauth/v2/authorization

followed by the access token url:

https://www.linkedin.com/oauth/v2/accessToken

was all that I really had to do (passing with the right parameters).

Read More

Sunday, April 23, 2017

Fetch LinkedIn Contacts/Connections

Leave a Comment

How to Fetch LinkedIn Contacts in iOS ? I read their API but in that api to fetch connections are not available any more. Is there are other alternate way to do it ? I tried OAUTH2 but by that I can only login and get user basic info.

This is how its done in Android . here

2 Answers

Answers 1

As it's mentioned here :

LinkedIn has restricted their open API access, and this no longer works.

This question may be possible duplicate question to: linkedin-api-get-information-about-my-all-connections

Answers 2

As stated here:

https://developer.linkedin.com/support/developer-program-transition

the access for connections have been removed from the public API. You can only get access if you apply to a Partner Program which requires an official review of your app.

The example code you posted for Android doesn't actually use the public API to get the connections, it uses the API to get an access token and then uses the following URL to get the connections in CSV format and shows it in a WebView:

https://www.linkedin.com/people/export-settings?exportNetwork=Export&outputType=microsoft_outlook

If you don't want to use a WebView, you could possible download the CSV output, and parse it to get the actual data.

To parse the CSV you can use a CSV library like the following: https://github.com/davedelong/CHCSVParser

Read More

Thursday, April 28, 2016

How to properly implement linkedIn login ?

Leave a Comment

I have an andorid app and i am trying to implement linkedIn login in it. LinkedIn SDK has been successfully integrated and i am getting user information as well along with the email address.

Here is how my application works for google login :

1) get access token on mobile

2) send email address with access token to server

3) fetch details of users with access token i received via webapi of google.

4) if the response email matches with the email received from mobile device then check for account exists or not of that email address . If not create account and login other wise login.


Problem with linkedIn :

The access token i have received belongs to mobile sdk and i cannot use the same token to make REST API request. (as per documentation)

Mobile vs. server-side access tokens

It is important to note that access tokens that are acquired via the Mobile SDK are only useable with the Mobile SDK, and cannot be used to make server-side REST API calls.

Similarly, access tokens that you already have stored from your users that authenticated using a server-side REST API call will not work with the Mobile SDK.

So how to verify details in step 3) i mentioned above on my webserver ?


Is It a disaster ? I am sure there has to be a way to do what i am trying to do, as there are many applications which let their users login through linkedin on their mobile apps.

Because if its not possible then anyone can easily change the email address the mobile app is sending to webserver after receiving from linkedin and i can login with any email address i want by doing that.

2 Answers

Answers 1

Like you said, you can't do it.

Instead you have to use a different approach, get the required info on the device, returned by LinkedIn and send it to your server. Use HTTPs connections to avoid MITM attacks.

If you app is downloaded from official information shouldn't be modified on device.

ANOTHER SECURITY MECHANISMS: If you want more security, you could for example encrypt data on server, send HASH to mobile, use your LinkedIn token to consult information and with another algorithm compare that data received is the same.

But I think that this a too expensive mechanism that should be resolved only using HTTPS connections and not downloading the APK from non official stores.

Answers 2

The docs state clearly that you can't use the AccessToken obtained from the Android SDK to make your own REST API calls.

However there's a way to make REST API calls with the mobile SDK, check the Making

Authenticated REST API calls from here: https://developer.linkedin.com/docs/android-sdk

If you want to retrieve the user profile info, you'll have to do it using the mobile SDK.

Read More