Hi,
Actually, one of the benefits of this library being built on top of twitter4j, pretty much the most popular library for Java support of our REST API, is that there is a lot of documentation online for how twitter4j works and this one was built to be close to that design (it’s more similar to ‘old school’ Java but well tested and stable core library).
The easiest way of understanding an example of how to manage multiple tokens is to authorize several users to use the debugging tool twurl. When you do so, a file called .twurlrc will be populated with those details, so your job is to mimic similar behavior to picking and choosing which user to OAuth as and storing those credentials somewhere (usually secure storage).
You can find some examples online of switching between different users with twitter4j like
You probably figured this out, but there are multiple ways of doing the auth setup, the most basic one is to just use Config Builder but there are also environment variables. It depends on how you want to set your environment up and whether you want to run on a server or local instance. One hello world style test program I wrote several months ago was like this:
public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("~")
.setOAuthConsumerSecret("~")
.setOAuthAccessToken("~")
.setOAuthAccessTokenSecret("~");
TwitterAdsFactory twitterAdsFactory = new twitter4j.TwitterAdsFactory(cb.build());
TwitterAds twitterAds = twitterAdsFactory.getAdsInstance();
TwitterAdsCampaignApi campaigns = twitterAds.getCampaignApi();
String accountID = "<insert your account ID>";
try {
BaseAdsListResponseIterable<Campaign> myCampaigns = campaigns.getAllCampaigns(accountID, null, null, false, 10, null, null);
for (BaseAdsListResponse<Campaign> campaign : myCampaigns){
System.out.println("name = " + campaign.getName());
}
} catch (TwitterException te) {
te.printStackTrace();
System.out.println(te.getMessage());
System.exit(-1);
}
}
Hope this helps!
John