Hi Priya,
This is very tricky. Y! Messenger buddy authorization is bi-directional.
When you want to add a buddy you should use this api call:
PUT <server>/v1/group/{groupname}/contact/{network}/{addeeId}
The below is my code in PHP:
public function buddy_add($budd)
{
$resu = $this->dbh->query("SELECT sess FROM login WHERE status=0");
$resu->setFetchMode(PDO::FETCH_NUM);
$toks = $resu->fetch();
$this->_sessid = $toks[0];
unset($toks);
$resu = $this->dbh->query("SELECT atk, atks FROM yimkeys WHERE status=0");
$resu->setFetchMode(PDO::FETCH_NUM);
$toks = $resu->fetch();
$params['oauth_version'] = '1.0';
$params['oauth_consumer_key'] = $this->_consumerkey;
$params['oauth_nonce'] = mt_rand();
$params['oauth_timestamp'] = time();
$params['oauth_token'] = $toks[0];
$params['oauth_signature_method'] = 'PLAINTEXT';
$params['oauth_signature'] = $this->plaintext_sig($this->_consumersecret, $toks[1]);
$header = $this->build_oauth_header($params, "yahooapis.com");
$headers[] = $header;
$req_url = $this->_rurl . '/v1/group/Buddies/contact/yahoo/'. $budd . '?_method=put&sid=' . $this->_sessid;
$headers[] = 'Content-Type: application/json;charset=utf-8';
$pbody = '{"authReason":"Hi' . $budd . ', Thanks for adding me"}';
$response = $this->do_post($req_url, $pbody, $headers);
return $response;
}
After your buddy accepts your request, you'll receive a notification, then you should this api call:
POST <server>/v1/buddyrequest/{network}/{adderId}
The below is my code in PHP:
public function buddy_auth($budd)
{
$resu = $this->dbh->query("SELECT sess FROM login WHERE status=0");
$resu->setFetchMode(PDO::FETCH_NUM);
$toks = $resu->fetch();
$this->_sessid = $toks[0];
unset($toks);
$resu = $this->dbh->query("SELECT atk, atks FROM yimkeys WHERE status=0");
$resu->setFetchMode(PDO::FETCH_NUM);
$toks = $resu->fetch();
$params['oauth_version'] = '1.0';
$params['oauth_consumer_key'] = $this->_consumerkey;
$params['oauth_nonce'] = mt_rand();
$params['oauth_timestamp'] = time();
$params['oauth_token'] = $toks[0];
$params['oauth_signature_method'] = 'PLAINTEXT';
$params['oauth_signature'] = $this->plaintext_sig($this->_consumersecret, $toks[1]);
$header = $this->build_oauth_header($params, "yahooapis.com");
$headers[] = $header;
$req_url = $this->_rurl . '/v1/buddyrequest/yahoo/' . $budd . '?sid=' . $this->_sessid;
$headers[] = 'Content-Type: application/json;charset=utf-8';
$pbody = '{"authReason":"Hi' . $budd . ', welcome to ESP, Bangalore"}';
$response = $this->do_post($req_url, $pbody, $headers);
return $response;
}
These are two methods in my class, if you want I can share my class.
And also I think you are passing the oauth authorization in the request url, it would be better if you pass it in the request header.
Thanks,
Karthik
Hi,
Thanks for reply.I did same thing still I am getting same error.Please give me some example.It's very urgent for me.
[code]
string presence_realm = "rcore1.messenger.yahooapis.com/v1/buddyrequest/yahoo/rachel_koshy40";
string postdata = "{}";
string url = "http://" + presence_realm + "?&sid=" + sessionId + "&oauth_consumer_key=" + oauth_consumer_key + "&oauth_signature_method=" +
oauth_signature_method + "&oauth_nonce=" + oauth_nonce + "&oauth_timestamp=" + oauth_timestamp + "&oauth_signature=" + oauth_signature
+ "&oauth_version=" + oauth_version + "&oauth_token=" + oauth_token;
string sessionid_request = fetchURL(url, true, postdata); [code]
Error:- The remote server returned an error: (500) Internal Server Error.
Thanks
Priya Soni.