analitics

Pages

Sunday, June 4, 2017

The development with python-instagram .

The python-instagram python module is a Python 2/3 client for the Instagram REST and Search APIs.
This python module requires httplib2, simplejson and six.
Instagram API uses the OAuth2 protocol for authentication, see docs.
C:\Python27\Scripts>pip install --upgrade  --trusted-host  pypi.python.org  
python-instagram
Collecting python-instagram
  Downloading python-instagram-1.3.2.tar.gz
Collecting simplejson (from python-instagram)
  Downloading simplejson-3.10.0-cp27-cp27m-win32.whl (66kB)
    100% |################################| 71kB 1.1MB/s
Requirement already up-to-date: httplib2 in c:\python27\lib\site-packages 
(from python-instagram)
Requirement already up-to-date: six in c:\python27\lib\site-packages 
(from python-instagram)
Building wheels for collected packages: python-instagram
  Running setup.py bdist_wheel for python-instagram ... done
 ...
Installing collected packages: simplejson, python-instagram
Successfully installed python-instagram-1.3.2 simplejson-3.10.0
Now about this python module:
C:\Python27>python.exe
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from instagram.client import InstagramAPI
>>> dir(InstagramAPI)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__',
 '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_make_relationship_shortcut', 
'_make_subscription_action', 'access_token_field', 'access_token_url', 'api_name', 
'approve_user_request', 'authorize_url', 'base_path', 'block_user', 'change_user_relationship',
 'create_media_comment', 'create_subscription', 'delete_comment', 'delete_subscriptions',
 'exchange_code_for_access_token', 'exchange_user_id_for_access_token', 
'exchange_xauth_login_for_access_token', 'follow_user', 'geography_recent_media', 
'get_authorize_login_url', 'get_authorize_url', 'host', 'ignore_user_request', 'like_media',
 'list_subscriptions', 'location', 'location_recent_media', 'location_search', 'media', 
'media_comments', 'media_likes', 'media_popular', 'media_search', 'media_shortcode', 'protocol',
 'redirect_uri', 'tag', 'tag_recent_media', 'tag_search', 'unblock_user', 'unfollow_user', 
'unlike_media', 'user', 'user_followed_by', 'user_follows', 'user_incoming_requests', 
'user_liked_media', 'user_media_feed', 'user_recent_media', 'user_relationship', 'user_search',
 'x_ratelimit', 'x_ratelimit_remaining']
If you have an Instagram account then just log in into instagram developer website.
Then fill the issue about your website the phone number and what do you want to build for your application check your agreement with Instagram.
Now you need to use Register Your Application and finally on Register a New Client.
About Register Your Application you need to fill them with data for your application ( basic info: Description, Company Name, Website URL, Contact email).
Select the tab Security and disable the Disable implicit OAuth.

About the token authorizations:

Is given to you with this words:

basic – to read a user’s profile info and media

or needs additional permission:

public_content – to read any public profile info and media on a user’s behalf
follower_list – to read the list of followers and followed-by users
comments – to post and delete comments on a user’s behalf
relationships – to follow and unfollow accounts on a user’s behalf
likes – to like and unlike media on a user’s behalf
The next step is to get access token then you need to add http://localhost link into Security tag from Manage Client.
Use this URL to get the access token by pasting it into your web browser.
https://instagram.com/oauth/authorize/?client_id=[CLIENT_ID_HERE]&redirect_uri=http://localhost&response_type=token&scope=public_content
Into the browser, you will see one page with one button for Authorizing access.
Press this button and into your browser address bar you will get the access token like:
http://localhost/#access_token=################
A simple python script to test it.
from time import sleep
from instagram.client import InstagramAPI

client_id="zzzzz"
client_secret="sssssssssssss"
redirect_uri= "http://xxxxx"
access_token="eeeee"

api = InstagramAPI(client_id=client_id, client_secret=client_secret)
print dir(api)
print api.api_name
To deal with python and Instagram is not very easy for me.
The main reason comes from errors and the Instagram API development way.
Some simple tasks are very hard to do.