当前位置: 首页>>代码示例>>Python>>正文


Python Client.authorization_url方法代码示例

本文整理汇总了Python中stravalib.Client.authorization_url方法的典型用法代码示例。如果您正苦于以下问题:Python Client.authorization_url方法的具体用法?Python Client.authorization_url怎么用?Python Client.authorization_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stravalib.Client的用法示例。


在下文中一共展示了Client.authorization_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: join

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
def join():
    c = Client()
    public_url = c.authorization_url(client_id=app.config['STRAVA_CLIENT_ID'],
                                     redirect_uri=url_for('.authorization', _external=True),
                                     approval_prompt='auto')
    private_url = c.authorization_url(client_id=app.config['STRAVA_CLIENT_ID'],
                                      redirect_uri=url_for('.authorization', _external=True),
                                      approval_prompt='auto',
                                      scope='view_private')
    return render_template('authorize.html', public_authorize_url=public_url, private_authorize_url=private_url)
开发者ID:aspalmer,项目名称:freezingsaddles,代码行数:12,代码来源:general.py

示例2: do_GET

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
    def do_GET(self):

        request_path = self.path

        parsed_path = urlparse.urlparse(request_path)

        client = Client()

        if request_path.startswith('/authorization'):
            self.send_response(200)
            self.send_header(six.b("Content-type"), six.b("text/plain"))
            self.end_headers()

            self.wfile.write(six.b("Authorization Handler\n\n"))
            code = urlparse.parse_qs(parsed_path.query).get('code')
            if code:
                code = code[0]
                token_response = client.exchange_code_for_token(client_id=self.server.client_id,
                                                              client_secret=self.server.client_secret,
                                                              code=code)
                access_token = token_response['access_token']
                self.server.logger.info("Exchanged code {} for access token {}".format(code, access_token))
                self.wfile.write(six.b("Access Token: {}\n".format(access_token)))
            else:
                self.server.logger.error("No code param received.")
                self.wfile.write(six.b("ERROR: No code param recevied.\n"))
        else:
            url = client.authorization_url(client_id=self.server.client_id,
                                           redirect_uri='http://localhost:{}/authorization'.format(self.server.server_port))

            self.send_response(302)
            self.send_header(six.b("Content-type"), six.b("text/plain"))
            self.send_header(six.b('Location'), six.b(url))
            self.end_headers()
            self.wfile.write(six.b("Redirect to URL: {}\n".format(url)))
开发者ID:hozn,项目名称:stravalib,代码行数:37,代码来源:auth_responder.py

示例3: join

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
def join():
    c = Client()
    public_url = c.authorization_url(
        client_id=config.STRAVA_CLIENT_ID,
        redirect_uri=url_for('.authorization', _external=True),
        approval_prompt='auto',
        scope=['read', 'activity:read', 'profile:read_all'],
    )
    private_url = c.authorization_url(
        client_id=config.STRAVA_CLIENT_ID,
        redirect_uri=url_for('.authorization', _external=True),
        approval_prompt='auto',
        scope=['read_all', 'activity:read_all', 'profile:read_all'],
    )
    return render_template('authorize.html',
                           public_authorize_url=public_url,
                           private_authorize_url=private_url,
                           competition_title=config.COMPETITION_TITLE)
开发者ID:hozn,项目名称:freezingsaddles,代码行数:20,代码来源:general.py

示例4: login

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
def login():
    c = Client()
    url = c.authorization_url(
        client_id=config.STRAVA_CLIENT_ID,
        redirect_uri=url_for('.logged_in', _external=True),
        approval_prompt='auto',
        scope=['read_all', 'activity:read_all', 'profile:read_all'],
    )
    return render_template('login.html',
                           authorize_url=url,
                           competition_title=config.COMPETITION_TITLE)
开发者ID:hozn,项目名称:freezingsaddles,代码行数:13,代码来源:general.py

示例5: get_activities_from_strava

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
def get_activities_from_strava():
    last_activity = None
    if not os.path.exists(STRAVA_ACCESS_TOKEN_STRING_FNAME):

        print '* Obtain a request token ...'
        strava_client = Client()
        auth_url = strava_client.authorization_url(client_id='601', redirect_uri='http://127.0.0.1:5000/authorisation')
        print auth_url

        auth_token = strava_client.exchange_code_for_token(client_id='601', client_secret='600580e02b4814c75c93d3a60e15077147895776', code = '74cc257e6bc370d9da44cabc8852f3667ad95515')

        print auth_token

        # write the access token to file; next time we just read it from file
        if DEBUG:
            print 'Writing file', STRAVA_ACCESS_TOKEN_STRING_FNAME


        fobj = open(STRAVA_ACCESS_TOKEN_STRING_FNAME, 'w')
        fobj.write(auth_token)
        fobj.close()

    else:
        if DEBUG:
            print 'Reading file', STRAVA_ACCESS_TOKEN_STRING_FNAME
        fobj = open(STRAVA_ACCESS_TOKEN_STRING_FNAME)
        access_token_string = fobj.read()

        print access_token_string
        #access_token = oauth.OAuthToken.from_string(access_token_string)

        strava_client = Client(access_token=access_token_string)
        activities = strava_client.get_activities(limit=10)

        # for activity in activities:
        #     details = strava_client.get_activity(activity_id=activity.id)
        #     print details.name
        #     print unithelper.kilometers(details.distance)
        #     print details.start_date_local
        #     print details.elapsed_time
        #     print details.calories
        #     print details.type
        #     print "------"
        # fobj.close()
        for activity in activities:
            last_activity = activity

    return strava_client.get_activity(activity_id=activity.id)
开发者ID:DCotterill,项目名称:StravaStats,代码行数:50,代码来源:FitBitConnector.py

示例6: details

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
def details(id):
    racer = Racer.query.get_or_404(id)
    teams = (Team.query.join(Participant)
             .join(Racer)
             .filter_by(id=id)
             .join(Race)
             .order_by(Race.date.desc())
             .all())
    current_team = racer.current_team
    if current_team in teams:
        teams.remove(current_team)

    current_year = datetime.date.today().year
    current_membership = (
        AcaMembership.query.with_entities(
            AcaMembership.paid, AcaMembership.season_pass)
        .filter(AcaMembership.year == current_year)
        .filter(AcaMembership.racer_id == racer.id)
    ).first()

    strava_client = Client()
    strava_client_id = current_app.config['STRAVA_CLIENT_ID']
    strava_url = (
        strava_client.authorization_url(
            client_id=strava_client_id,
            redirect_uri=url_for('racer.authorize_strava', _external=True),
            state=racer.id,
            approval_prompt='force'))

    if racer.strava_access_token:
        access_token = racer.strava_access_token
        try:
            strava_client = Client(access_token)
            strava_client.get_athlete()
        except Exception:
            racer.strava_access_token = None
            racer.strava_id = None
            racer.strava_email = None
            racer.strava_profile_url = None
            racer.strava_profile_last_fetch = None
            current_app.logger.info('forced strava deauth %s[%d]', racer.name, racer.id)
            db.session.commit()

    return render_template('racer/details.html', racer=racer,
                           current_membership=current_membership,
                           current_team=current_team, teams=teams,
                           strava_url=strava_url)
开发者ID:jyundt,项目名称:oval,代码行数:49,代码来源:views.py

示例7: index

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
def index(request):
    access_token = request.session.get('access_token', None)
    if access_token is None:
        # if access_token is NOT in session, kickoff the oauth exchange
        client = Client()
        url = client.authorization_url(
            client_id=os.environ.get('STRAVA_CLIENT_ID', None),
            redirect_uri='http://' + settings.ALLOWED_HOSTS[0] + '/authorization'
            # redirect_uri='http://127.0.0.1:8000/authorization'
        )
        context = {'auth_url': url}
        return render(request, 'index.html', context)

    # otherwise, load authorized user
    client = Client(access_token=access_token)

    athlete_id = request.session.get('athlete_id', None)
    if athlete_id is None:
        # if athlete is NOT already in session, get athlete
        # (attempting to reduce calls to the API)
        athlete = client.get_athlete()
        request.session['athlete_id'] = athlete.id
        request.session['firstname'] = athlete.firstname

        try:
            Athlete.objects.get(strava_id=athlete.id)
        except Athlete.DoesNotExist:
            new_athlete = Athlete()
            new_athlete.strava_id = athlete.id
            new_athlete.first_name = athlete.firstname
            new_athlete.last_name = athlete.lastname
            new_athlete.city = athlete.city
            new_athlete.state = athlete.state
            new_athlete.country = athlete.country
            new_athlete.save()

    return render(request, 'welcome_landing.html')
开发者ID:wilson0xb4,项目名称:strava-friend-breaker,代码行数:39,代码来源:views.py

示例8: redirectAuth

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
def redirectAuth():
    client = Client()
    url = client.authorization_url(client_id=MY_STRAVA_CLIENT_ID,
                                   redirect_uri=request.url)
    return redirect(url)
开发者ID:swuerth,项目名称:StravaDevChallenge,代码行数:7,代码来源:simplest.py

示例9: Client

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
from stravalib import Client
#import urllib3.contrib.pyopenssl
#urllib3.contrib.pyopenssl.inject_into_urllib3()
import thresher, os
from models import Activity, Athlete

client = Client()

# Got from Strava after registering on website
MY_STRAVA_CLIENT_ID = "9558"
MY_STRAVA_CLIENT_SECRET = "734e394ff653703abaef7c7c061cc8d685241a10"

# a url sending visitor to strava's website for authentication
# THIS MUST BE UPDATED FOR WEB USE, strava website must be updated as well
#stravaURL = client.authorization_url(client_id=MY_STRAVA_CLIENT_ID, redirect_uri='http://reddlee.pythonanywhere.com/authorization')
stravaURL = client.authorization_url(client_id=MY_STRAVA_CLIENT_ID, redirect_uri='http://127.0.0.1:8000/authorization')

def index(request):
    return render(request, 'stravaChimp/index.html', {'c':stravaURL})
    
#
# visitors sent to this page after agreeing to allow our site to use their strava
def authorization(request):
    client = Client()
    code = request.GET['code']
    access_token = client.exchange_code_for_token(client_id=MY_STRAVA_CLIENT_ID, client_secret=MY_STRAVA_CLIENT_SECRET, code=code)   
    
    # making a global variable to be used across views. don't know how this will work in practice
    
    client = Client(access_token=access_token)
    athlete = client.get_athlete() # Get current athlete details
开发者ID:rgilman33,项目名称:stravachimp,代码行数:33,代码来源:views.py

示例10: login

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
def login():
    c = Client()
    url = c.authorization_url(client_id=app.config['STRAVA_CLIENT_ID'],
                              redirect_uri=url_for('.logged_in', _external=True),
                              approval_prompt='auto')
    return render_template('login.html', authorize_url=url)
开发者ID:hozn,项目名称:stravalib,代码行数:8,代码来源:server.py

示例11: Client

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
from config import *

from stravalib import Client
import sys

client = Client()

if len( sys.argv ) == 1:

  url = client.authorization_url(client_id=STRAVA_CLIENT_ID,
                                           redirect_uri='http://localhost', scope='view_private,write' )
  print "Paste this URL in your browser:"
  print
  print url
  print
  print "And then re-run this script like so: "
  print "\t" + sys.argv[0] + " <code>"

elif sys.argv[1] == 'test':
  client = Client( access_token=STRAVA_ACCESS_TOKEN)
  print client.get_athlete()

else:
  code = sys.argv[1]
  access_token = client.exchange_code_for_token(client_id=STRAVA_CLIENT_ID,
                                                client_secret=STRAVA_CLIENT_SECRET,
                                                code=code)
  print "Your Strava access token is: " + access_token
开发者ID:erikgranlund,项目名称:mmr_to_fitbit_sync,代码行数:30,代码来源:get_strava_access_token.py

示例12: Client

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
from stravalib import Client
client = Client()

CLIENT_ID = "CLIENT ID"
CLIENT_SECRET = "CLIENT SECRET"

url = client.authorization_url(
    client_id=CLIENT_ID,
    scope="write",
    redirect_uri='http://localhost')
# Go to that URL and retrieve the code
print(url)

CODE = "PUT THE CODE HERE"

access_token = client.exchange_code_for_token(
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET,
    code=CODE)

print(access_token)
开发者ID:jd,项目名称:runtastic2strava,代码行数:23,代码来源:get-token.py

示例13: index

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
def index(request):
    client = Client()
    url = client.authorization_url(client_id=11103,
                                   redirect_uri='http://localhost:8000/authorization')
    ##TODO: Take out of code for version control
    return HttpResponse('Hello world, You are at the Strava Auth landing page. <a href="{0}">Click Here to authorize</a>'.format(url))
开发者ID:jarrodolson,项目名称:StravaPyServer,代码行数:8,代码来源:views.py

示例14: connect

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
def connect():
	client = Client()
	url = client.authorization_url(client_id = app.vars['client_id'], \
		redirect_uri = 'http://127.0.0.1:5000/authorization')
	return render_template('connect.html', connect_url = url)
开发者ID:paulsavala,项目名称:strava-power-profiler,代码行数:7,代码来源:views.py

示例15: Client

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import authorization_url [as 别名]
    cp.read(os.path.expanduser('~/.stravacli'))
    cat = None
    if cp.has_section('API'):
        cat = cp.get('API', 'ACCESS_TOKEN') if 'access_token' in cp.options('API') else None

while True:
    client = Client(cat)
    try:
        athlete = client.get_athlete()
    except requests.exceptions.ConnectionError:
        p.error("Could not connect to Strava API")
    except Exception as e:
        print("NOT AUTHORIZED", file=stderr)
        print("Need Strava API access token. Launching web browser to obtain one.", file=stderr)
        client = Client()
        authorize_url = client.authorization_url(client_id=cid, redirect_uri='http://stravacli-dlenski.rhcloud.com/auth', scope='view_private,write')
        webbrowser.open_new_tab(authorize_url)
        client.access_token = cat = raw_input("Enter access token: ")
    else:
        if not cp.has_section('API'):
            cp.add_section('API')
        if not 'ACCESS_TOKEN' in cp.options('API') or cp.get('API', 'ACCESS_TOKEN', None)!=cat:
            cp.set('API', 'ACCESS_TOKEN', cat)
            cp.write(open(os.path.expanduser('~/.stravacli'),"w"))
        break

print("Authorized to access account of {} {} (id {:d}).".format(athlete.firstname, athlete.lastname, athlete.id))

#####

for ii,f in enumerate(args.activities):
开发者ID:grigory-rechistov,项目名称:stravacli,代码行数:33,代码来源:stravaup.py


注:本文中的stravalib.Client.authorization_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。