0

I'm running a background task and in this task I want to consult the UserConnection database and manually connect to each user's twitter account and pull some data from twitter using users operation.

The table provides the following fields

 USERID
 PROVIDERID
 PROVIDERUSERID
 RANK
 DISPLAYNAME
 PROFILEURL
 IMAGEURL
 ACCESSTOKEN
 SECRET
 REFRESHTOKEN
 EXPIRETIME

How do I use these to connect to the user's account (PROVIDERID = "twitter")?

Olayinka
  • 2,813
  • 2
  • 25
  • 43

2 Answers2

0

If I am following your question correctly... You can get the Users Twitter Profile by

   TwitterProfile profile = getUserOperations().getUserProfile(Long.valueOf(userId));

OR

TwitterProfile profile =     getUserOperations().getUserProfile(screenName);

Of course you would need user or twitter app authorization via TwitterTemplate. Hope this helps.

Thanks,

Paul

Paul John
  • 1,626
  • 1
  • 13
  • 15
0

After pulling the connections from the database, all I had to do was create a Twitter from TwitterTemplate.

List<Connection> connections = connectionRepository.findAllConnections();
for (Connection conn : connections) {
    Twitter twitter = new TwitterTemplate(twitterAppKey, twitterAppSecret, conn.getAccessToken(), conn.getSecret());
    //now I can run the operations
    System.out.println(twitter.userOperations().getScreenName());
}
Olayinka
  • 2,813
  • 2
  • 25
  • 43