def callback(): # make sure the response came from Spotify if request.args.get('state') != session['state_key']: return render_template('index.html', error='State failed.') if request.args.get('error'): return render_template('index.html', error='Spotify error.') else: code = request.args.get('code') session.pop('state_key', None) # get access token to make requests on behalf of the user payload = getToken(code) if payload != None: session['token'] = payload[0] session['refresh_token'] = payload[1] session['token_expiration'] = time.time() + payload[2] else: return render_template('index.html', error='Failed to access token.') current_user = getUserInformation(session) session['user_id'] = current_user['id'] logging.info('new user:'******'user_id']) return redirect(session['previous_url'])
import functions, codecs #Server Information - specify the REST endpoint and desired URL protocol ("SOAP" or "REST") restURL = "http://sampleserver6.arcgisonline.com/arcgis/rest/services" protocol = "REST" #If you wish to use a token, set getToken to true and specify following parameters getToken = False tokenURL = "http://sampleserver6.arcgisonline.com/arcgis/tokens/generateToken" username = "******" password = "******" #Get Token and Service List from Server if getToken == True: token = functions.getToken(tokenURL, username, password)['token'] serviceList = functions.restCrawl(restURL, token, protocol) else: serviceList = functions.restCrawl(restURL, "", protocol) #Write service list to text file log = codecs.open("services.txt",encoding='utf-8', mode="w+") for service in serviceList: print service log.write(service + "\n") log.close()