Reputation: 6820
I am working on a simple email importer script. From what posts on this site have said, the ones that are for sale are either dodgy, or not worth the money spent, and as I know PHP and JS I thought this can't be hard, after all I have worked with Twitter API, and Facebook API.
However I seem to ran into a little bump in the road.
You see I am using Yahoo's very own script Yahoo.inc - http://developer.yahoo.com/social/sdk/php/
And all is going well as possible. However when I try to get the contacts I seem not to be able to. Now I have in the API settings for my app, ask for read request for contacts so I know it not that issue.
Here is my code I am using
$contacts = $user->getContacts();
However it seems not work work, it's like I am missing something. What is the correct way to get emails from the getContacts function Yahoo offers?
Upvotes: 3
Views: 5012
Reputation: 602
Search this method getContacts()
from yahoo api file (i.e Yahoo.inc), and increase the limit to 500. Initially it would be 10.
Upvotes: 0
Reputation: 6510
Looking at github you can see that the yahoo-yos-php package is deprecated. it will be replaced by the yahoo-yos-php5 package. Perhaps you should download that and try using it instead.
BTW, yahoo-yos-php uses a YOS API call (doc) to fetch the data while yahoo-yos-php5 uses YQL queries. So the end result of using the new package is the same as @mithunsatheesh solution only packaged in a yahoo distribution.
Here is a link to the class, and the function itself:
public function getContacts($guid = null, $offset = 0, $limit = 10)
{
if($guid == null && !is_null($this->token))
{
$guid = $this->token->yahoo_guid;
}
$rsp = $this->yql(sprintf('SELECT * FROM social.contacts(%s,%s) WHERE guid="%s"', $offset, $limit, $guid));
return isset($rsp->query->results) ? $rsp->query->results : false;
}
Upvotes: 1
Reputation: 27845
instead of the getContacts(), you can use a yql query for that:
$session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
$query = sprintf("select * from social.contacts where guid=me;");
$response = $session->query($query);
/**** printing the contact emails starts ****/
if(isset($response)){
foreach($response->query->results->contact as $id){
foreach($id->fields as $subid){
if( $subid->type == 'email' )
echo $subid->value."<br />";
}
}
}
/**** printing the contact emails ends ****/
Upvotes: 4