0
votes

I'm facing one issue while sending messages to linked connections. I have used two APIs, https://api.linkedin.com/v1/people/ to update profile and https://api.linkedin.com/v1/people/~/mailbox to sending messages to connections.

Updating the profile is working fine for me, and I am even getting one 1-level connection. But the problem is arising when sending messages to connections.

Below is the XML code I'm using to send messages.

$xmlPostData = '<?xml version="1.0" encoding="UTF-8"?>

    <mailbox-item>
        <recipients>
            <recipient>
                <person path="/people/'.$iMemberId.'" />
            </recipient>
        </recipients>
        <subject>Invitation to Connect</subject>
        <body>Please Join On Eduroadmap</body>
        <item-content>
            <invitation-request>
                <connect-type>friend</connect-type>
                <authorization>
                    <name>'.$sAuthName.'</name>
                    <value>'.$sAuthValue.'</value>
                </authorization>
            </invitation-request>
        </item-content>
    </mailbox-item>';

In above code, $iMemberId, $sAuthName , $sAuthValue are the connection details which I have retrieved from https://api.linkedin.com/v1/people/~/connections api.

Below is the curl I am using to post the above XML.

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$sUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$xmlPostData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

In the above code, $sUrl is => https://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token=, and I'm appending an access token that is correct I am sure.

What am I missing? I have tried a lot, but I found nothing.

1

1 Answers

0
votes

Please visit http://developer.linkedin.com/thread/3255. Anyway, from where did you get $sAuthName and $sAuthValue? It is obtained from the https://api.linkedin.com/v1/people/~/connections** API and using (api-standard-profile-request). Request?

These are the steps:

Example: the API call must me api-standard-profile request.

  1. http://api.linkedin.com/v1/people/id=abcdj32:(first-name,last-name,api-standard-profile-request)
  2. Get the $sAuthName and $sAuthValue for your need from the generated response of the above API call. You can get it from the value tag inside the <api-standard-profile-request>, and it will be like this: <value>name:6hhdh6</value>
  3. For your need, $sAuthName = name & $sAuthValue =6hhdh6
  4. $iMemberId should not be id data from the XML response
  5. Scope should be "w_messages" enabled
  6. XML data should be proper with these

Try these.