簡體   English   中英

Twitter4j身份驗證錯誤

[英]Twitter4j Authentication error

我需要獲取一個人說virat kohli的鳴叫次數,關注者數量和朋友計數。我使用Twitter4j jar,我的代碼如下所示

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.User;
import twitter4j.auth.OAuthAuthorization;
import twitter4j.conf.ConfigurationBuilder;


public class HomePage {
public static void main(String[] args) throws IOException, TwitterException {
    Properties props=new Properties();
    InputStream input=new FileInputStream(args[0]);
    props.load(input);
    ConfigurationBuilder conf=new ConfigurationBuilder();
         conf.setDebugEnabled(true).setOAuthConsumerKey(props.getProperty("ConsumerKey")).setOAuthConsumerSecret(props.getProperty("ConsumerSecret")).setOAuthAccessToken(props.getProperty("AccessToken")).setOAuthAccessTokenSecret(props.getProperty("AccessTokenSecret"));
    OAuthAuthorization auth = new OAuthAuthorization(conf.build());
     Twitter twitter = new TwitterFactory().getInstance(auth);
    // User user = twitter.verifyCredentials();
    User user=twitter.showUser("@imVkohli");
    System.out.println(user.getStatusesCount());
    System.out.println(user.getFriendsCount());
    System.out.println(user.getFollowersCount());




}

}

所有鍵都放置在屬性文件中,並且iam傳遞屬性文件的路徑作為運行時參數。 我得到以下異常

Exception in thread "main" 401:Authentication credentials    (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set   valid consumer key/secret, access token/secret, and the system clock is in sync.
message - Could not authenticate you
code - 32

如果我嘗試獲取時間表,則我不會收到此錯誤。 代碼中有錯誤嗎?

問題是線

User user=twitter.showUser("@imVkohli");

它必須是屏幕名稱,而不是twitter處理程序。 守則必須是

User user=twitter.showUser("imVkohli");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM