コード例 #1
0
def instagram_callback():
    instagram = get_instagram_auth()
    state = instagram.authorization_url(InstagramOAuth.get_auth_uri(),
                                        access_type='offline')
    instagram = get_instagram_auth(state=state)
    if 'code' in request.url:
        code_url = (((request.url.split('&'))[0]).split('='))[1]
        token = instagram.fetch_token(
            InstagramOAuth.get_token_uri(),
            authorization_url=request.url,
            code=code_url,
            client_secret=InstagramOAuth.get_client_secret())
        response = instagram.get(
            'https://api.instagram.com/v1/users/self/media/recent/?access_token='
            + token.get('access_token', '')).json()

        for el in response.get('data'):
            filename, uploaded_file = uploaded_file_provided_by_url(
                el['images']['standard_resolution']['url'])
            upload(uploaded_file, '/image/' + filename)
            update_user_details(instagram=el['caption']['from']['username'])
            if session['next_redirect']:
                return redirect(session['next_redirect'])
    else:
        flash("OAuth Authorization error. Please try again later.")
    return redirect(url_for('admin.login_view'))
コード例 #2
0
def instagram_callback():
    instagram = get_instagram_auth()
    state = instagram.authorization_url(InstagramOAuth.get_auth_uri(), access_type='offline')
    instagram = get_instagram_auth(state=state)
    if 'code' in request.url:
        code_url = (((request.url.split('&'))[0]).split('='))[1]
        token = instagram.fetch_token(InstagramOAuth.get_token_uri(),
                                      authorization_url=request.url,
                                      code=code_url,
                                      client_secret=InstagramOAuth.get_client_secret())
        response = instagram.get('https://api.instagram.com/v1/users/self/media/recent/?access_token=' + token.get('access_token', '')).json()
        for el in response.get('data'):
            response_file = urlopen(el['images']['standard_resolution']['url'])

            filename = str(time.time()) + '.jpg'
            file_path = os.path.realpath('.') + '/static/temp/' + filename
            fh = open(file_path, "wb")
            fh.write(response_file.read())
            fh.close()
            img = UploadedFile(file_path, filename)
            print img
            background_url = upload(img, '/image/' + filename)
            print background_url

    return 'Not implemented'
コード例 #3
0
def get_instagram_auth(state=None, token=None):
    if token:
        return OAuth2Session(InstagramOAuth.get_client_id(), token=token)
    if state:
        return OAuth2Session(InstagramOAuth.get_client_id(), state=state,
                             redirect_uri=InstagramOAuth.get_redirect_uri())
    # scope = "+".join(InstagramOAuth.SCOPE)
    oauth = OAuth2Session(InstagramOAuth.get_client_id(), redirect_uri=InstagramOAuth.get_redirect_uri())
    return oauth
コード例 #4
0
def get_instagram_auth(state=None, token=None):
    if token:
        return OAuth2Session(InstagramOAuth.get_client_id(), token=token)
    if state:
        return OAuth2Session(InstagramOAuth.get_client_id(), state=state,
                             redirect_uri=InstagramOAuth.get_redirect_uri())
    # scope = "+".join(InstagramOAuth.SCOPE)
    oauth = OAuth2Session(InstagramOAuth.get_client_id(), redirect_uri=InstagramOAuth.get_redirect_uri())
    return oauth
コード例 #5
0
def instagram_callback():
    instagram = get_instagram_auth()
    state = instagram.authorization_url(InstagramOAuth.get_auth_uri(), access_type='offline')
    instagram = get_instagram_auth(state=state)
    if 'code' in request.url:
        code_url = (((request.url.split('&'))[0]).split('='))[1]
        token = instagram.fetch_token(InstagramOAuth.get_token_uri(),
                                      authorization_url=request.url,
                                      code=code_url,
                                      client_secret=InstagramOAuth.get_client_secret())
        response = instagram.get('https://api.instagram.com/v1/users/self/media/recent/?access_token=' + token.get('access_token', '')).json()
        for el in response.get('data'):
            background_url = save_file_provided_by_url(el['images']['standard_resolution']['url'])
            print background_url

    return 'Not implemented'
コード例 #6
0
def instagram_callback():
    instagram = get_instagram_auth()
    state = instagram.authorization_url(InstagramOAuth.get_auth_uri(), access_type='offline')
    instagram = get_instagram_auth(state=state)
    if 'code' in request.url:
        code_url = (((request.url.split('&'))[0]).split('='))[1]
        token = instagram.fetch_token(InstagramOAuth.get_token_uri(),
                                      authorization_url=request.url,
                                      code=code_url,
                                      client_secret=InstagramOAuth.get_client_secret())
        response = instagram.get(
            'https://api.instagram.com/v1/users/self/media/recent/?access_token=' + token.get('access_token',
                                                                                              '')).json()
        for el in response.get('data'):
            filename, uploaded_file = uploaded_file_provided_by_url(el['images']['standard_resolution']['url'])
            upload(uploaded_file, '/image/' + filename)

    flash("OAuth Authorization error. Please try again later.")
    return redirect(url_for('admin.login_view'))
コード例 #7
0
 def connect_instagram(self):
     instagram = get_instagram_auth()
     instagram_auth_url, state = instagram.authorization_url(InstagramOAuth.get_auth_uri(), access_type='offline')
     return redirect(instagram_auth_url)
コード例 #8
0
 def connect_instagram(self):
     instagram = get_instagram_auth()
     print InstagramOAuth.get_auth_uri()
     instagram_auth_url, state = instagram.authorization_url(InstagramOAuth.get_auth_uri(), access_type='offline')
     return redirect(instagram_auth_url)