简体   繁体   中英

DirectMessage authentication in Twitter4j API

I am working with a twitter client project which is using the Twitter4j API. My program is able to read tweets from the timeline, see followers and follower list, but whenever I want to access DirectMessage it shows

errors:code:93-message:This application is not allowed to
access or delete your direct messages

I have following authentication-

 Twitter twitter = new TwitterFactory().getInstance();
 twitter.setOAuthConsumer(Static.CONSUMER_KEY,Static.CONSUMER_SECRET);
 AccessToken accessToken = Static.CURRENT_USER_ACCESS_TOKEN;
 twitter.setOAuthAccessToken(accessToken);
 twitter = Static.CURRENT_TWITTER;

Any idea what causes the error above?

When access directmessage using twitter4j, an error shows "unable to parse '3577866941' as integer".I have set the value of ACCESS_TOKEN,ACCESSTOKEN_SECRET,CONSUMER_KEY,CONSUMER_SECRET which I got from dev.twitter but it crashes when the application runs.I use twitter4j-core-2.1.8-SNAPSHOT.jar as library.The code is given bellow.

public ResponseList<DirectMessage> dmList=null;
public static AccessToken token = new AccessToken(ACCESS_TOKEN, ACCESSTOKEN_SECRET);
TwitterFactory factory = new TwitterFactory();
twitter = factory.getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
twitter.setOAuthAccessToken(token); 
try {
    dmList = twitter.getDirectMessages(new Paging(1,15));
} catch (TwitterException e) {
    e.printStackTrace();
}

Thanks.

You need "Read, Write and Direct Messages" permission to read / delete direct messages. Make sure that your application is in the appropriate role at https://dev.twitter.com/apps .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM