我正在尝试使用 python 生成 Oauth URL 并且能够生成,但是当我从 Snap 点击 URL 时,我只收到“出了问题”,没有其他消息或错误...
下面是我的带有Python代码的snapchat
from urllib.parse import urlencode, quote
SNAPCHAT_API_KEY = "#####################"
SNAPCHAT_API_SECRET = "##################"
SNAPCHAT_OAUTH_CALLBACK_URL = "https://localhost:3000"
class SnapchatAPI:
def __init__(self):
self.api_key = SNAPCHAT_API_KEY
self.api_secret = SNAPCHAT_API_SECRET
self.oauth_callback_url = SNAPCHAT_OAUTH_CALLBACK_URL
self.permissions = ["display_name", "external_id"]
self.auth_url = "https://accounts.snapchat.com/accounts/oauth2/auth"
def snapchat_login(self):
try:
query_param_string = urlencode(
{
"client_id": self.api_key,
"redirect_uri": self.oauth_callback_url,
"response_type": "code",
"scope": " ".join(self.permissions),
},
quote_via=quote,
)
# if state:
# query_param_string += f"&state={state}"
return f"{self.auth_url}?{query_param_string}"
except Exception as e:
print(e)
return None
我得到的网址是...
https://accounts.snapchat.com/accounts/oauth2/auth?client_id=##############&redirect_uri=https%3A%2F%2Flocalhost%3A3000%2Ftwitter&response_type=code&scope=display_name%20external_id
这里有什么问题以及如何解决它?或者有没有更好的方法用 python 实现 Snapchat 登录?
我对 python 不太了解,但也许我创建 url 的 java 函数可以帮助你:
static String AUTHORIZATION_ENDPOINT = "https://accounts.snapchat.com/login/oauth2/authorize";
public static String generateAuthorizationUrl(String scopes) {
return AUTHORIZATION_ENDPOINT +
"?client_id=" + CLIENT_ID +
"&redirect_uri=" + URLEncoder.encode(REDIRECT_URI, StandardCharsets.UTF_8) +
"&response_type=code" +
"&scope=" + URLEncoder.encode(scopes);
}