在代码中生成新的 OAuthAccessToken 和 OAuthAccessTokenSecret

Generate new OAuthAccessToken and OAuthAccessTokenSecret in code

我可以在代码中生成新的 OAuthAccessToken 和 OAuthAccessTokenSecret 吗?可能正在使用 twitter4j?我有:

configurationBuilder.setDaemonEnabled(true)
    .setOAuthConsumerKey("MyCoonsumerKey")
    .setOAuthConsumerSecret("MyConsumerSecret")
    .setOAuthAccessToken("MyAccessToken")
    .setOAuthAccessTokenSecret("MyAccessTokenSecret");

但我想在代码中生成新的令牌。我可以做吗?怎么样?

对此的简单回答是:

,不能通过Twitter4J自行生成OAuthAccessToken或OAuthAccessTokenSecret

取自https://dev.twitter.com/oauth/overview,我们了解到:

In order to make authorized calls to Twitter’s APIs, an application must first obtain an OAuth access token on behalf of a Twitter user (or, issue Application-only authenticated requests, when user context is not required).

此外,...

... an access token will be invalidated if a user explicitly revokes an application in the their Twitter account settings, or if Twitter suspends an application.

结论:

您必须在“他们的 Twitter 帐户设置”中生成访问令牌和密码。作为参考,请在以下位置找到完整指南:https://dev.twitter.com/oauth/overview/introduction

请注意,需要手机 phone 号码。