首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有书签的Tweepy错误,TypeError:无法保存的类型:'OAuth2Token‘

带有书签的Tweepy错误,TypeError:无法保存的类型:'OAuth2Token‘
EN

Stack Overflow用户
提问于 2022-07-18 18:37:39
回答 1查看 75关注 0票数 0

我正试图编写一个删除书签的脚本,我遵循文档这里直到tweepy客户端步骤,然后尝试从这里进行书签操作。

下面是我的代码,只有在第25行到达时才会得到一个错误:

代码语言:javascript
复制
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")

对于无法控制的类型错误,我该怎么办?编辑:添加了完整的错误跟踪

代码语言:javascript
复制
    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流的文档没有设置我认为的访问令牌。怪异

EN

回答 1

Stack Overflow用户

发布于 2022-07-18 20:54:28

好吧,我解决了。

我在文档中注意到,访问键应该是一个字符串。我通过执行以下操作获得了访问密钥的字符串:

代码语言:javascript
复制
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:

代码语言:javascript
复制
print("The client access token is ", client.access_token) 

所以这很酷

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73027084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档