{"id":531,"date":"2010-05-28T12:25:05","date_gmt":"2010-05-28T19:25:05","guid":{"rendered":"http:\/\/sp2hari.com\/?p=531"},"modified":"2020-06-20T08:30:02","modified_gmt":"2020-06-20T08:30:02","slug":"importing-contacts-from-yahoo-mail-using-oauth","status":"publish","type":"post","link":"https:\/\/sp2hari.com\/index.php\/2010\/05\/28\/importing-contacts-from-yahoo-mail-using-oauth\/","title":{"rendered":"Importing Contacts from Yahoo Mail using OAuth"},"content":{"rendered":"<p>Importing contacts from mail accounts using OAuth is a long solved problem which doesn&#8217;t have a good implementation. I googled and googled for a good library which imports contacts from Yahoo\/GMail\/Hotmail. Finally, I was forced to create one by myself. Here are the instructions on how to get it up and running for Yahoo Mail in your server in 2 mins.<\/p>\n<p>1. You need a Yahoo API Key to fetch contacts from Yahoo. Proceed to <a href=\"https:\/\/developer.apps.yahoo.com\/dashboard\/createKey.html\">Yahoo Developer Dashboard<\/a> and create a key.<\/p>\n<p>Application URL in the createKey page is the URL to which you will be redirected to after a successful\/failed login attempt.<br \/>\nApplication Domain is be your domain name.<br \/>\nChoose &#8220;This app requires access to private user data.&#8221; in the Access Scope and under the options which appear below that, select &#8220;Read&#8221; access for &#8220;Yahoo! Contacts&#8221;.<br \/>\nStore the API Key, Shared Secret and Application ID carefully.<\/p>\n<p>2. Download Yahoo Social SDK for PHP from <a href=\"http:\/\/developer.yahoo.com\/social\/sdk\/php\/\">http:\/\/developer.yahoo.com\/social\/sdk\/php\/<\/a><\/p>\n<p>$this-&gt;config-&gt;item(&#8216;yahoo_consumerkey&#8217;) is your Yahoo API Key.<br \/>\n$this-&gt;config-&gt;item(&#8216;yahoo_consumersecret&#8217;) is your Yahoo Shared Secret.<br \/>\n$this-&gt;config-&gt;item(&#8216;yahoo_applicationurl&#8217;) is your Application URL you provided in Step 1.<br \/>\n$this-&gt;config-&gt;item(&#8216;yahoo_applicationid&#8217;) is your Yahoo Application ID.<\/p>\n<p>3. Add the following code where the user has to select Yahoo Mail<\/p>\n<p><code><br \/>\n&lt;a href=\"&lt;?php echo YahooSession::createAuthorizationUrl($this-&gt;config-&gt;item('yahoo_consumerkey'), $this-&gt;config-&gt;item('yahoo_consumersecret'), $this-&gt;config-&gt;item('yahoo_applicationurl').'?data=abc'); ?&gt;\"&gt;Fetch Yahoo Contacts&lt;\/a&gt;<br \/>\n<\/code><\/p>\n<p>You may remove the ?data=abc if you don&#8217;t want to pass any data to Yahoo. Anything you pass here can retrieved back at Application URL as GET parameters.<\/p>\n<p>4. Include the required files from the opensocial SDK library and then add the following snippet to the Application URL you provided in Step 1.<br \/>\n<code><br \/>\nif (YahooSession::hasSession($this-&gt;config-&gt;item('yahoo_consumerkey'), $this-&gt;config-&gt;item('yahoo_consumersecret'), $this-&gt;config-&gt;item('yahoo_applicationid')))<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;$session = YahooSession::requireSession($this-&gt;config-&gt;item('yahoo_consumerkey'), $this-&gt;config-&gt;item('yahoo_consumersecret'), $this-&gt;config-&gt;item('yahoo_applicationid'));<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;$user = $session-&gt;getSessionedUser();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;$contacts = $user-&gt;getContacts(0, 1000);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;foreach ($contacts-&gt;contacts-&gt;contact as $contact)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach ($contact-&gt;fields as $field)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($field-&gt;type == \"email\")<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$emails[] = $field-&gt;value;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/$_GET['data'] will be equal to \"abc\" at this page.<br \/>\n}<br \/>\n\/\/$emails array has the email addresses of all the contacts.<br \/>\n<\/code><br \/>\n5. That&#8217;s it folks. It is that simple.<\/p>\n<p>Further reading :<br \/>\n1. <a href=\"http:\/\/developer.yahoo.com\/social\/sdk\/php\/\">http:\/\/developer.yahoo.com\/social\/sdk\/php\/<\/a><br \/>\n2. <a href=\"http:\/\/developer.yahoo.com\/oauth\/\">http:\/\/developer.yahoo.com\/oauth\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Importing contacts from mail accounts using OAuth is a long solved problem which doesn&#8217;t have a good implementation. I googled and googled for a good library which imports contacts from Yahoo\/GMail\/Hotmail. Finally, I was forced to create one by myself. Here are the instructions on how to get it up &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-531","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/posts\/531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/comments?post=531"}],"version-history":[{"count":14,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"predecessor-version":[{"id":1354,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/posts\/531\/revisions\/1354"}],"wp:attachment":[{"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}