Erik's Weblog 2.0

December 20, 2013 +2 more...

[@825]

linkedin-j & Access to posting shares denied

This morning I noticed that my blog wasn't able to share on Linkedin anymore. I use the linkedin-j library to automatically share new blog posts on Linkedin. I rightfully assumed that my OAuth access token had expired. Upon resetting the token, I got the following error:

Access to posting shares denied
After a bit of research I was able to ascertain that the linkedin-j library was not requesting write access permission, which apparently is now required.

If was able to fix the problem by adding the following code right before the token request:
final Field field = LinkedInApiUrls.class.getField("LINKED_IN_OAUTH_REQUEST_TOKEN_URL");
field.setAccessible(true);
final Field modifiersField = java.lang.reflect.Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null, LinkedInApiUrls.LINKED_IN_OAUTH_REQUEST_TOKEN_URL + "?scope=rw_nus+r_basicprofile");
You gotta love the reflection API.

I can't really take the credit for the solution, I found it on stackoverflow.

Post a comment

 

Comment Preview