I am trying to implement Twitter's Three-legged OAuth flow, but have started to get an exception back from Twitter when running the first stage of the OAuth process, see below
The Code
import urllib.parse
from typing import NamedTuple
import oauth2 as oauth
TWITTER_CONSUMER_KEY = ""
TWITTER_CONSUMER_SECRET = ""
TWITTER_REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token"
class TempToken(NamedTuple):
oauth_token: str
oauth_token_secret: str
oauth_callback_confirmed: bool
def get_temp_token(c: oauth.Client, encoding: str = "utf-8") -> TempToken:
"""
Step 1: Get a request token. This is a temporary token that is used for
having the user authorize an access token and to sign the request to obtain
said access token.
:param c: oauth Client
:param encoding: "utf-8"
:return: TempToken
"""
resp, content = c.request(TWITTER_REQUEST_TOKEN_URL, "GET")
if resp.status != 200:
raise Exception(f"Invalid response {resp['reason']}")
return TempToken(
**dict(
urllib.parse.parse_qsl(
content.decode(encoding)
)
)
)
if __name__ == "__main__":
consumer = oauth.Consumer(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
client = oauth.Client(consumer)
temp_token = get_temp_token(client)
print(temp_token)
The Problem
The line:
resp, content = c.request(TWITTER_REQUEST_TOKEN_URL, "GET")
Now results in:
<?xml version='1.0' encoding='UTF-8'?><errors><error code="69">The given URL is considered malware</error></errors>
I am unsure why this is happening as yesterday everything was working perfectly.
from Twitter API treating URL as Malware
No comments:
Post a Comment