我正试图编写一个删除书签的脚本,我遵循文档这里直到tweepy客户端步骤,然后尝试从这里进行书签操作。
下面是我的代码,只有在第25行到达时才会得到一个错误:
import tweepy
oauth2_user_handler = tweepy.OAuth2UserHandler(
client_id="id",
redirect_uri="https://127.0.0.1",
scope=["bookmark.read", "bookmark.write",
"tweet.read","users.read"],
client_secret="secret"
)
print(oauth2_user_handler.get_authorization_url())
verifier = input("Enter whole callback URL: ")
access_token = oauth2_user_handler.fetch_token(verifier)
client = tweepy.Client(access_token)
response = client.get_bookmarks(expansions="author_id,attachments.media_keys",
tweet_fields="created_at,public_metrics,attachments",
user_fields="username,name,profile_image_url",
media_fields="public_metrics,url,height,width,alt_text")对于无法控制的类型错误,我该怎么办?编辑:添加了完整的错误跟踪
Traceback (most recent call last):
File "C:\Users\RosenKids\Desktop\Manim projects\tweepyBookmarkTesting.py", line 25, in <module>
client.get_bookmarks(expansions="author_id,attachments.media_keys", #I need the access token! <-- learned this from reading the documentation for type error!
File "C:\Python310\lib\site-packages\tweepy\client.py", line 363, in get_bookmarks
id = self._get_authenticating_user_id()
File "C:\Python310\lib\site-packages\tweepy\client.py", line 245, in _get_authenticating_user_id
return self._get_oauth_2_authenticating_user_id(
TypeError: unhashable type: 'OAuth2Token'我做了更多的研究,它说,当访问令牌未设置时,get_bookmarks将返回一个TypeError。但我不是已经做过了吗?我运行了一个测试,以查看access_token属性设置为什么,并返回None,这意味着PKCE2.0流的文档没有设置我认为的访问令牌。怪异
发布于 2022-07-18 20:54:28
好吧,我解决了。
我在文档中注意到,访问键应该是一个字符串。我通过执行以下操作获得了访问密钥的字符串:
accessToken = oauth2_user_handler.fetch_token(verifier)
print("The returned access token is ", accessToken)
accessCopy = input("Copy paste the access token here \n >")
client = tweepy.Client(accessCopy)虽然这个语句仍然返回none,这意味着access_token属性为none,但是书签函数工作了一个OK:
print("The client access token is ", client.access_token) 所以这很酷
https://stackoverflow.com/questions/73027084
复制相似问题