...
val httpServletRequest = Box.asA[HTTPRequestServlet](data.request).get.req
val provider = ManagerSocialAuth.managerLinkedIn.connect(SocialAuthUtil.getRequestParametersMap(httpServletRequest))
val profile: Profile = provider.getUserProfile
val contactList = provider.getContactList
// here contactList connect and get a correct list
val params = data._params.foldRight(""){(d,c) =>
{if (c == "") "?" else (c + "&") } + d._1 + "=" + d._2.headOption.map((v: String) => v).getOrElse("") }
// Using samen provider or a new provider (provider2) error is the same
val man = ManagerSocialAuth.managerLinkedIn
ManagerSocialAuth.setSocialAuthConfig(man)
(man.getAuthenticationUrl("linkedin", ManagerSocialAuth.linkedInSuccessUrl), man)
val provider2 = ManagerSocialAuth.managerLinkedIn.connect(SocialAuthUtil.getRequestParametersMap(httpServletRequest))
val profile2: Profile = provider2.getUserProfile
val paramData = SocialAuthUtil.getRequestParametersMap(httpServletRequest)
val paramHeader = Map("Content-Type" -> "application/xml")
val emailList = contactList.asScala.toList.foreach(c => {
if (c.getId == "JQv7hkZATe") {
val body =
<mailbox-item>
<recipients>
<recipient>
<person path='/people/~' />
</recipient>
<recipient>
<person path="/people/JQv7hkZATe" />
</recipient>
</recipients>
<subject>Congratulations on your new position.</subject>
<body>You're certainly the best person for the job!</body>
</mailbox-item>
// Error get in this line
val res = provider2.api("https://api.linkedin.com/v1/people/~/mailbox", "POST", paramData, paramHeader.asJava, body.toString)
val info = res.getResponseBodyAsString(Constants.ENCODING)
}
})
....
Message: java.io.IOException: Server returned HTTP response code: 401 for URL: https://api.linkedin.com/v1/people/~/mailbox
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:526)
sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1675)
sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1673)
java.security.AccessController.doPrivileged(Native Method)
sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1671)
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1244)
sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
org.brickred.socialauth.util.Response.getResponseBodyAsString(Response.java:103)
code.lib.rest.SocialAuthApi$$anonfun$1$$anonfun$5.apply(SocialAuthApi.scala:137)
code.lib.rest.SocialAuthApi$$anonfun$1$$anonfun$5.apply(SocialAuthApi.scala:118)
scala.collection.immutable.List.foreach(List.scala:381)
code.lib.rest.SocialAuthApi$$anonfun$1.applyOrElse(SocialAuthApi.scala:118)
code.lib.rest.SocialAuthApi$$anonfun$1.applyOrElse(SocialAuthApi.scala:49)
scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
net.liftweb.http.rest.ListServeMagic$$anon$14.apply(RestHelper.scala:741)
net.liftweb.http.rest.ListServeMagic$$anon$14.apply(RestHelper.scala:734)
Caught and thrown by:
Message: java.io.IOException: Server returned HTTP response code: 401 for URL: https://api.linkedin.com/v1/people/~/mailbox
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:2678)
sun.net.www.protocol.https.HttpsURLConnectionImpl.getHeaderField(HttpsURLConnectionImpl.java:291)
org.brickred.socialauth.util.Response.getResponseBodyAsString(Response.java:97)
code.lib.rest.SocialAuthApi$$anonfun$1$$anonfun$5.apply(SocialAuthApi.scala:137)
code.lib.rest.SocialAuthApi$$anonfun$1$$anonfun$5.apply(SocialAuthApi.scala:118)
scala.collection.immutable.List.foreach(List.scala:381)
code.lib.rest.SocialAuthApi$$anonfun$1.applyOrElse(SocialAuthApi.scala:118)
code.lib.rest.SocialAuthApi$$anonfun$1.applyOrElse(SocialAuthApi.scala:49)
scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
net.liftweb.http.rest.ListServeMagic$$anon$14.apply(RestHelper.scala:741)
net.liftweb.http.rest.ListServeMagic$$anon$14.apply(RestHelper.scala:734)
net.liftweb.http.rest.RestHelper$class.apply(RestHelper.scala:522)
code.lib.rest.SocialAuthApi$.apply(SocialAuthApi.scala:25)
code.lib.rest.SocialAuthApi$.apply(SocialAuthApi.scala:25)
net.liftweb.util.NamedPF$$anonfun$applyBox$1.apply(NamedPartialFunction.scala:97)
net.liftweb.util.NamedPF$$anonfun$applyBox$1.apply(NamedPartialFunction.scala:97)