{"id":13,"date":"2018-01-16T02:03:05","date_gmt":"2018-01-16T02:03:05","guid":{"rendered":"http:\/\/api.intelligentonlinetools.com\/diy\/?p=13"},"modified":"2018-02-01T02:16:20","modified_gmt":"2018-02-01T02:16:20","slug":"web-api-save-pocket-app-instapaper-app","status":"publish","type":"post","link":"http:\/\/api.intelligentonlinetools.com\/diy\/web-api-save-pocket-app-instapaper-app\/","title":{"rendered":"Web API to Save to Pocket App and Instapaper App"},"content":{"rendered":"<p>As we surf the web we find a lot of information that we might use later. We use different applications (Pocket app, Instapaper, Diigo, Evernote or other apps) to save links or notes what we find.<\/p>\n<p>While many of the above applications have a lot of great features there still a lot of opportunities to automate some processes using web API that many of applications provide now.<\/p>\n<p>This will allow to extend application functionality and eliminate some manual processes.<\/p>\n<p>For Example: You have about 20 links that you want to send to pocket like application.<br \/>\nAnother example: When you add link to one application you may be want also save link or note to Pocket app or to Instapaper application.<br \/>\nOr may be you want automatically (through script) extract links from some web sites and save them to your Pocket app.<\/p>\n<p>In today post we will look at few examples that allow you start to do this. We will check how to use Pocket API and Instapaper API with python programming.<\/p>\n<h3>API for Pocket App<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/01\/pocket.jpg\" alt=\"pocket API\" width=\"56\" height=\"51\" class=\"alignnone size-full wp-image-21\"  style=\"float:left\" \/> Pocket, previously known as Read It Later, is an application and service for managing a reading list of articles from the Internet. It is available on many different devices including web browsers. (Wikipedia)<br \/>\nThere is great post[1] that is showing how to set up API for it. This post has detailed screenshots how to get all the needed identification information for successful login.<\/p>\n<p>In summary you need get online consumer key for your api application then obtain token code via script. Then you can access the link that will include token and do authorization of application. After this you can use API for sending links.<\/p>\n<p>Below is the summary python script to send the link to Pocket app including previous steps:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport requests\r\n\r\n# can be any for link\r\nredirect_link = &quot;google.com&quot;\r\nconsumer_key=&quot;xxxxxxxx&quot;\r\n# obtain consume key online\r\n#connect to pocket API to get token code\r\npocket_api = requests.post('https:\/\/getpocket.com\/v3\/oauth\/request',\r\n         data = {'consumer_key':consumer_key,\r\n                 'redirect_uri':redirect_link})\r\n\r\npocket_api.status_code       #if 200, it means all ok.\r\n\r\nprint(pocket_api.headers)               \r\nprint (pocket_api.text)\r\n\r\n#remove 'code='\r\ntoken= pocket_api.text[5:]\r\nprint (token)\r\nurl=&quot;https:\/\/getpocket.com\/auth\/authorize?request_token=&quot; + token + &quot;&amp;redirect_uri=&quot; + redirect_link \r\n\r\nimport webbrowser\r\nwebbrowser.open_new(url) # opens in default browser\r\n#click on Authorize button in webbrowser\r\n\r\n# Once authoration done you can post as below (need uncomment code below)  \r\n&quot;&quot;&quot;\r\npocket_add = requests.post('https:\/\/getpocket.com\/v3\/add',\r\n       data= {'url': 'https:\/\/getpocket.com\/developer\/apps\/new',\r\n              'consumer_key':consumer_key,\r\n              'access_token': token})\r\nprint (pocket_add.status_code)\r\n\r\n&quot;&quot;&quot;\r\n<\/pre>\n<h3>API for Instapaper<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/01\/Instapaper.jpg\" alt=\"\" width=\"30\" height=\"47\" class=\"alignnone size-full wp-image-20\" style=\"float:left\" \/> Instapaper is a bookmarking service owned by Pinterest. It allows web content to be saved so it can be &#8220;read later&#8221; on a different device, such as an e-reader, smartphone, tablet. (Wikipedia)<br \/>\nBelow is the code example how to send link to Instapaper. The code example is based on the script that I found on Internet [2]<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport urllib, sys\r\n\r\ndef error(msg):\r\nsys.exit(msg)\r\n\r\ndef main():\r\napi = 'https:\/\/www.instapaper.com\/api\/add'\r\n\r\nparams = urllib.parse.urlencode({\r\n'username' : &quot;actual_user_name&quot;,\r\n'password' : &quot;actual_password&quot;,\r\n'url' : &quot;https:\/\/www.actual_url&quot;,\r\n'title' : &quot;actual_title&quot;,\r\n'selection' : &quot;description&quot;\r\n\r\n}).encode(&quot;utf-8&quot;)\r\n\r\nr = urllib.request.urlopen(api, params)\r\n\r\nstatus = r.getcode()\r\n\r\nif status == 201:\r\n\r\nprint('%s saved as %s' % (r.headers['Content-Location'], r.headers['X-Instapaper-Title']))\r\nelif status == 400:\r\nerror('Status 400: Bad request or exceeded the rate limit. Probably missing a required parameter, such as url.')\r\nelif status == 403:\r\nerror('Status 403: Invalid username or password.')\r\nelif status == 500:\r\nerror('Status 500: The service encountered an error. Please try again later')\r\n\r\nif __name__ == '__main__':\r\nmain()\r\n<\/pre>\n<p><strong>References<\/strong><br \/>\n1. <a href=http:\/\/saideepchandg.github.io\/pocket\/2016\/02\/21\/add-pocket-api-to-your-site.html target=\"_blank\">Add Pocket API using Python &#8211; Tutorial<\/a><br \/>\n2. <a href=https:\/\/gist.github.com\/sliem\/1289424 target=\"_blank\">Instapaper<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As we surf the web we find a lot of information that we might use later. We use different applications (Pocket app, Instapaper, Diigo, Evernote or other apps) to save links or notes what we find. While many of the above applications have a lot of great features there still a lot of opportunities to &#8230; <a title=\"Web API to Save to Pocket App and Instapaper App\" class=\"read-more\" href=\"http:\/\/api.intelligentonlinetools.com\/diy\/web-api-save-pocket-app-instapaper-app\/\" aria-label=\"More on Web API to Save to Pocket App and Instapaper App\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false},"categories":[4],"tags":[5,8,7,9,6],"_links":{"self":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts\/13"}],"collection":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":8,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":25,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts\/13\/revisions\/25"}],"wp:attachment":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}