From 555678008e7b465cc8dde1b51e348c876e4c90da Mon Sep 17 00:00:00 2001 From: beaglebao Date: Tue, 24 Jul 2018 21:31:32 +0800 Subject: [PATCH] amend and specification --- fixtures/user_recent_media.json | 1 - instagram/bind.py | 6 +++--- instagram/client.py | 2 +- instagram/helper.py | 2 +- instagram/models.py | 6 +++--- instagram/oauth2.py | 13 +++++-------- python_instagram.egg-info/SOURCES.txt | 5 ++++- sample_app.py | 4 ++-- specification.txt | 11 +++++++++++ 9 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 specification.txt diff --git a/fixtures/user_recent_media.json b/fixtures/user_recent_media.json index cb6fece7..0a8b3781 100644 --- a/fixtures/user_recent_media.json +++ b/fixtures/user_recent_media.json @@ -156,6 +156,5 @@ "id": "3", "location": null } - ] } diff --git a/instagram/bind.py b/instagram/bind.py index cce758bf..480e056f 100644 --- a/instagram/bind.py +++ b/instagram/bind.py @@ -10,12 +10,12 @@ re_path_template = re.compile('{\w+}') - +#create a function def encode_string(value): return value.encode('utf-8') \ if isinstance(value, six.text_type) else str(value) - +#create a InstagramClientError class class InstagramClientError(Exception): def __init__(self, error_message, status_code=None): self.status_code = status_code @@ -161,7 +161,7 @@ def _do_api_request(self, url, method="GET", body=None, headers=None): return api_responses, self._build_pagination_info(content_obj) else: raise InstagramAPIError(status_code, content_obj['meta']['error_type'], content_obj['meta']['error_message']) - + #GET to get list of all resources and information about them def _paginator_with_url(self, url, method="GET", body=None, headers=None): headers = headers or {} pages_read = 0 diff --git a/instagram/client.py b/instagram/client.py index 624bc0ec..2558386b 100644 --- a/instagram/client.py +++ b/instagram/client.py @@ -234,7 +234,7 @@ def _make_subscription_action(method, include=None, exclude=None): objectify_response=False, signature=signature, ) - +#POST to create new subscription,DELETE to remove subscription,GET to get resources list create_subscription = _make_subscription_action('POST') list_subscriptions = _make_subscription_action('GET') delete_subscriptions = _make_subscription_action('DELETE', exclude=['object_id'], include=['id']) diff --git a/instagram/helper.py b/instagram/helper.py index 62bcf5b5..f6ca6785 100644 --- a/instagram/helper.py +++ b/instagram/helper.py @@ -1,7 +1,7 @@ import calendar from datetime import datetime - +#create two functions def timestamp_to_datetime(ts): return datetime.utcfromtimestamp(float(ts)) diff --git a/instagram/models.py b/instagram/models.py index d2517ca2..5947d436 100644 --- a/instagram/models.py +++ b/instagram/models.py @@ -1,7 +1,7 @@ from .helper import timestamp_to_datetime import six - +#create class class ApiModel(object): @classmethod @@ -44,12 +44,12 @@ def __unicode__(self): class Media(ApiModel): - + def __init__(self, id=None, **kwargs): self.id = id for key, value in six.iteritems(kwargs): setattr(self, key, value) - + #create and define functions def get_standard_resolution_url(self): if self.type == 'image': return self.images['standard_resolution'].url diff --git a/instagram/oauth2.py b/instagram/oauth2.py index 053b1be8..817733e1 100644 --- a/instagram/oauth2.py +++ b/instagram/oauth2.py @@ -54,9 +54,7 @@ def exchange_user_id_for_access_token(self, user_id): def exchange_xauth_login_for_access_token(self, username, password, scope=None): """ scope should be a tuple or list of requested scope access levels """ req = OAuth2AuthExchangeRequest(self) - return req.exchange_for_access_token(username=username, password=password, - scope=scope) - + return req.exchange_for_access_token(username=username, password=password,scope=scope) class OAuth2AuthExchangeRequest(object): def __init__(self, api): @@ -72,7 +70,7 @@ def _url_for_authorize(self, scope=None): client_params.update(scope=' '.join(scope)) url_params = urlencode(client_params) return "%s?%s" % (self.api.authorize_url, url_params) - + #Dict client_params def _data_for_exchange(self, code=None, username=None, password=None, scope=None, user_id=None): client_params = { "client_id": self.api.client_id, @@ -115,7 +113,6 @@ def exchange_for_access_token(self, code=None, username=None, password=None, sco raise OAuth2AuthExchangeError(parsed_content.get("error_message", "")) return parsed_content['access_token'], parsed_content['user'] - class OAuth2Request(object): def __init__(self, api): self.api = api @@ -128,10 +125,10 @@ def _generate_sig(self, endpoint, params, secret): def url_for_get(self, path, parameters): return self._full_url_with_params(path, parameters) - + #GET to get list and informations of resources def get_request(self, path, **kwargs): return self.make_request(self.prepare_request("GET", path, kwargs)) - + #POST to create new resources def post_request(self, path, **kwargs): return self.make_request(self.prepare_request("POST", path, kwargs)) @@ -227,7 +224,7 @@ def prepare_request(self, method, path, params, include_secret=False): url = self._full_url(path) return url, method, body, headers - + #GET used to get information of resource def make_request(self, url, method="GET", body=None, headers=None): headers = headers or {} if not 'User-Agent' in headers: diff --git a/python_instagram.egg-info/SOURCES.txt b/python_instagram.egg-info/SOURCES.txt index 02db67d7..8910a41c 100644 --- a/python_instagram.egg-info/SOURCES.txt +++ b/python_instagram.egg-info/SOURCES.txt @@ -1,4 +1,7 @@ setup.py +tests.py +sample_app.py +get_access_token.py instagram/__init__.py instagram/bind.py instagram/client.py @@ -12,4 +15,4 @@ python_instagram.egg-info/SOURCES.txt python_instagram.egg-info/dependency_links.txt python_instagram.egg-info/requires.txt python_instagram.egg-info/top_level.txt -python_instagram.egg-info/zip-safe \ No newline at end of file +python_instagram.egg-info/zip-safe diff --git a/sample_app.py b/sample_app.py index 82cc13a9..eb6f507a 100644 --- a/sample_app.py +++ b/sample_app.py @@ -12,7 +12,7 @@ } app = beaker.middleware.SessionMiddleware(bottle.app(), session_opts) - +#Dict the CONFIG CONFIG = { 'client_id': '', 'client_secret': '', @@ -30,7 +30,7 @@ def process_tag_update(update): reactor = subscriptions.SubscriptionsReactor() reactor.register_callback(subscriptions.SubscriptionType.TAG, process_tag_update) - +#Define and access a route for url ending with '/' @route('/') def home(): try: diff --git a/specification.txt b/specification.txt new file mode 100644 index 00000000..e48a632b --- /dev/null +++ b/specification.txt @@ -0,0 +1,11 @@ +Every new app created on the instagram Platform starts in Sandbox mode.Apps in this mode can use any API endpoint but are restricted to a limited number of users and media.This is great for developing and testing your app.To go Live and fully access Instagram content,you will need to submit your application for review and approval.Once reviewed,you will only be able to request users the Permision Scopes for which your app was approved.Because of this,your application may not be able to use some API endpoints unless the corresponding permissions were reviewed and approved.The review process allows us to ensure an authentic and consistent experience for the Instagram Community.The app review process aims to help community members more granularly control how their content is being shared through 3rd party apps and that those apps are building compliant use case. + +Criteria for Review +1.Brand and policy compliance +-App must comply with Instagram Platform Policy and Instagram Brand Guideliness. + +2.Submission quality +-Notes must be clear,concise.We will not approve submissions with insufficient notes. + +3.Video screencast quality +-The video screencast must show the Instagram login experience of your app,proper credentials and the usage of every permission you are requesting.We will not approve submissions if you do not provide a clear and working screencast.