Error when redirecting with Twitter oauth
I'm new to Flask and I'm trying to do do oauth with Twitter using Twython. Following is my code (development version):
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
callback_url = 'http://127.0.0.1:5000/verify'
@app.route('/')
def hello(name=None):
return render_template('index.html', name=name)
@app.route('/auth', methods=['POST'])
@cross_origin()
def obtain_auth_url():
global OAUTH_TOKEN, OAUTH_TOKEN_SECRET
social_network = request.get_json()['social_network']
if social_network == 'facebook':
return ''
elif social_network == 'twitter':
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens(callback_url)
OAUTH_TOKEN = auth['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret']
redirect_url= auth['auth_url']
response = redirect(redirect_url)
response.headers = {'Access-Control-Allow-Origin': 'https://api.twitter.com/'}
print('redirect_url: ',redirect_url)
return response
@app.route("/verify")
def get_verification():
global OAUTH_TOKEN
global OAUTH_TOKEN_SECRET
twitter = Twython(APP_KEY, APP_SECRET,OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
final_step = twitter.get_authorized_tokens(request.args['oauth_verifier'])
OAUTH_TOKEN2 = final_step['oauth_token']
OAUTH_TOKEN_SECRET2 = final_step['oauth_token_secret']
return 'OK!</br> OAUTH TOKEN:' + OAUTH_TOKEN2 +'</br> OAUTH TOKEN SECRET: '+ OAUTH_TOKEN_SECRET2
Note that in the code, I add the header Access-Control-Allow-Origin
to enable the redirect to twitter api domain. If I don't include the header, it throws a cross origin block error.
However, on the browser (Firefox), is said:
XML Parsing Error: syntax error Location: http://127.0.0.1:5000/auth
Line Number 1, Column 55:
Clearly, the endpoint /auth
has been reached because I can see the redirect url via log, but I don't understand why I have the error.
Please help.
python flask twython
add a comment |
I'm new to Flask and I'm trying to do do oauth with Twitter using Twython. Following is my code (development version):
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
callback_url = 'http://127.0.0.1:5000/verify'
@app.route('/')
def hello(name=None):
return render_template('index.html', name=name)
@app.route('/auth', methods=['POST'])
@cross_origin()
def obtain_auth_url():
global OAUTH_TOKEN, OAUTH_TOKEN_SECRET
social_network = request.get_json()['social_network']
if social_network == 'facebook':
return ''
elif social_network == 'twitter':
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens(callback_url)
OAUTH_TOKEN = auth['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret']
redirect_url= auth['auth_url']
response = redirect(redirect_url)
response.headers = {'Access-Control-Allow-Origin': 'https://api.twitter.com/'}
print('redirect_url: ',redirect_url)
return response
@app.route("/verify")
def get_verification():
global OAUTH_TOKEN
global OAUTH_TOKEN_SECRET
twitter = Twython(APP_KEY, APP_SECRET,OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
final_step = twitter.get_authorized_tokens(request.args['oauth_verifier'])
OAUTH_TOKEN2 = final_step['oauth_token']
OAUTH_TOKEN_SECRET2 = final_step['oauth_token_secret']
return 'OK!</br> OAUTH TOKEN:' + OAUTH_TOKEN2 +'</br> OAUTH TOKEN SECRET: '+ OAUTH_TOKEN_SECRET2
Note that in the code, I add the header Access-Control-Allow-Origin
to enable the redirect to twitter api domain. If I don't include the header, it throws a cross origin block error.
However, on the browser (Firefox), is said:
XML Parsing Error: syntax error Location: http://127.0.0.1:5000/auth
Line Number 1, Column 55:
Clearly, the endpoint /auth
has been reached because I can see the redirect url via log, but I don't understand why I have the error.
Please help.
python flask twython
add a comment |
I'm new to Flask and I'm trying to do do oauth with Twitter using Twython. Following is my code (development version):
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
callback_url = 'http://127.0.0.1:5000/verify'
@app.route('/')
def hello(name=None):
return render_template('index.html', name=name)
@app.route('/auth', methods=['POST'])
@cross_origin()
def obtain_auth_url():
global OAUTH_TOKEN, OAUTH_TOKEN_SECRET
social_network = request.get_json()['social_network']
if social_network == 'facebook':
return ''
elif social_network == 'twitter':
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens(callback_url)
OAUTH_TOKEN = auth['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret']
redirect_url= auth['auth_url']
response = redirect(redirect_url)
response.headers = {'Access-Control-Allow-Origin': 'https://api.twitter.com/'}
print('redirect_url: ',redirect_url)
return response
@app.route("/verify")
def get_verification():
global OAUTH_TOKEN
global OAUTH_TOKEN_SECRET
twitter = Twython(APP_KEY, APP_SECRET,OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
final_step = twitter.get_authorized_tokens(request.args['oauth_verifier'])
OAUTH_TOKEN2 = final_step['oauth_token']
OAUTH_TOKEN_SECRET2 = final_step['oauth_token_secret']
return 'OK!</br> OAUTH TOKEN:' + OAUTH_TOKEN2 +'</br> OAUTH TOKEN SECRET: '+ OAUTH_TOKEN_SECRET2
Note that in the code, I add the header Access-Control-Allow-Origin
to enable the redirect to twitter api domain. If I don't include the header, it throws a cross origin block error.
However, on the browser (Firefox), is said:
XML Parsing Error: syntax error Location: http://127.0.0.1:5000/auth
Line Number 1, Column 55:
Clearly, the endpoint /auth
has been reached because I can see the redirect url via log, but I don't understand why I have the error.
Please help.
python flask twython
I'm new to Flask and I'm trying to do do oauth with Twitter using Twython. Following is my code (development version):
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
callback_url = 'http://127.0.0.1:5000/verify'
@app.route('/')
def hello(name=None):
return render_template('index.html', name=name)
@app.route('/auth', methods=['POST'])
@cross_origin()
def obtain_auth_url():
global OAUTH_TOKEN, OAUTH_TOKEN_SECRET
social_network = request.get_json()['social_network']
if social_network == 'facebook':
return ''
elif social_network == 'twitter':
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens(callback_url)
OAUTH_TOKEN = auth['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret']
redirect_url= auth['auth_url']
response = redirect(redirect_url)
response.headers = {'Access-Control-Allow-Origin': 'https://api.twitter.com/'}
print('redirect_url: ',redirect_url)
return response
@app.route("/verify")
def get_verification():
global OAUTH_TOKEN
global OAUTH_TOKEN_SECRET
twitter = Twython(APP_KEY, APP_SECRET,OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
final_step = twitter.get_authorized_tokens(request.args['oauth_verifier'])
OAUTH_TOKEN2 = final_step['oauth_token']
OAUTH_TOKEN_SECRET2 = final_step['oauth_token_secret']
return 'OK!</br> OAUTH TOKEN:' + OAUTH_TOKEN2 +'</br> OAUTH TOKEN SECRET: '+ OAUTH_TOKEN_SECRET2
Note that in the code, I add the header Access-Control-Allow-Origin
to enable the redirect to twitter api domain. If I don't include the header, it throws a cross origin block error.
However, on the browser (Firefox), is said:
XML Parsing Error: syntax error Location: http://127.0.0.1:5000/auth
Line Number 1, Column 55:
Clearly, the endpoint /auth
has been reached because I can see the redirect url via log, but I don't understand why I have the error.
Please help.
python flask twython
python flask twython
asked Nov 16 at 8:16
lenhhoxung
1,10311338
1,10311338
add a comment |
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53333877%2ferror-when-redirecting-with-twitter-oauth%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53333877%2ferror-when-redirecting-with-twitter-oauth%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown