本文整理汇总了Java中net.dean.jraw.http.UserAgent类的典型用法代码示例。如果您正苦于以下问题:Java UserAgent类的具体用法?Java UserAgent怎么用?Java UserAgent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserAgent类属于net.dean.jraw.http包,在下文中一共展示了UserAgent类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ReddigramBot
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
ReddigramBot() throws Exception {
timer = new Timer();
config = BotConfig.configFromFile(new File("config.json"));
dataFile = DataFile.load(this);
client = new RedditClient(UserAgent.of("server", "xyz.mkotb.reddigram", "1.0", config.redditUsername()));
telegramBot = TelegramBot.login(config.botApiKey());
liveManager = new LiveManager(this);
telegramBot.getEventsManager().register(new InlineListener(this));
telegramBot.getEventsManager().register(new CommandListener(this));
telegramBot.startUpdates(true);
log("Successfully logged in");
timer.scheduleAtFixedRate(new OAuthTask(this), 0L, 3500000L); // every 58 minutes reauth.
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (dataFile != null) {
dataFile.save();
}
}
}, 0L, 600000L); // every 10m save data file
}
示例2: onCreate
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnUserlessAuth = (Button) findViewById(R.id.btnUserlessAuth);
btnUserlessAuth.setOnClickListener(this);
Button btnUserAuth = (Button) findViewById(R.id.btnUserAuth);
btnUserAuth.setOnClickListener(this);
Button btnCheckStatus = (Button) findViewById(R.id.btnCheckStatus);
btnCheckStatus.setOnClickListener(this);
Button btnRefreshToken = (Button) findViewById(R.id.btnRefreshToken);
btnRefreshToken.setOnClickListener(this);
Button btnLoadTopPost = (Button) findViewById(R.id.btnLoadSubmission);
btnLoadTopPost.setOnClickListener(this);
Button btnLogout = (Button) findViewById(R.id.btnLogout);
btnLogout.setOnClickListener(this);
RedditClient redditClient = new RedditClient(UserAgent.of("android",
"com.gmail.jorgegilcavazos.androidjrawsample", "v0.0.1", "yourusername"));
TokenStore store = new AndroidTokenStore(
PreferenceManager.getDefaultSharedPreferences(this));
RefreshTokenHandler refreshTokenHandler = new RefreshTokenHandler(store, redditClient);
AuthenticationManager manager = AuthenticationManager.get();
manager.init(redditClient, refreshTokenHandler);
}
示例3: ScraperBot
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
public ScraperBot() throws OAuthException {
UserAgent agent = UserAgent.of("script", "io.github.<username>", "v0.1", "<username>");
client = new RedditClient(agent);
Credentials cred = Credentials.script("<username>", "<password>", "<public key>", "<private key>");
OAuthData data = client.getOAuthHelper().easyAuth(cred);
client.authenticate(data);
posts = new HashMap<>();
}
示例4: init
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
public void init() {
log.info("got here");
try {
UserAgent myUserAgent = UserAgent.of("desktop", "com.flowchat", "v0.1", "dessalines");
redditClient = new RedditClient(myUserAgent);
Credentials credentials = Credentials.script(DataSources.PROPERTIES.getProperty("reddit_username"),
DataSources.PROPERTIES.getProperty("reddit_password"),
DataSources.PROPERTIES.getProperty("reddit_client_id"),
DataSources.PROPERTIES.getProperty("reddit_client_secret"));
OAuthData authData = redditClient.getOAuthHelper().easyAuth(credentials);
redditClient.authenticate(authData);
} catch (OAuthException e) {
e.printStackTrace();
}
}
示例5: buildUserAgent
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
private UserAgent buildUserAgent(){
String platform = properties.getProperty("user.agent.platform");
String appId = properties.getProperty("user.agent.app.id");
String version = properties.getProperty("user.agent.version");
String redditUsername = properties.getProperty("user.agent.reddit.username");
return UserAgent.of(platform, appId, version, redditUsername);
}
示例6: JrawReaderHelper
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
private JrawReaderHelper(@NonNull Resources resources) {
UserAgent myUserAgent = UserAgent.of("mobile", "io.github.jotran.reader",
"v0.1", "reader-app");
mRedditClient = new RedditClient(myUserAgent);
mOAuthHelper = mRedditClient.getOAuthHelper();
final String CLIENT_ID = resources.getString(R.string.reddit_client_id);
mCredentials = Credentials.installedApp(CLIENT_ID, REDIRECT_URL);
}
示例7: authenticate
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
public AuthHelper authenticate() throws NetworkException, OAuthException{
AuthHelper helper = new AuthHelper();
UserAgent myUserAgent = UserAgent.of("desktop", "YouTubeBot", "0.1", "-YouTubeBot-");
RedditClient redditClient = new RedditClient(myUserAgent);
Credentials credentials = Credentials.script("-YouTubeBot-", "Ash3win#", "WnBQphrJ2jWY5A", "bJmaYXBDHUNfPGRpSEUPHOtLrIk");
OAuthData authData = redditClient.getOAuthHelper().easyAuth(credentials);
redditClient.authenticate(authData);
helper.setCredentials(credentials);
helper.setRedditClient(redditClient);
return(helper);
}
示例8: getAuthenticatedClient
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
private RedditClient getAuthenticatedClient(String profileName) {
String token;
RedditClient reddit = new RedditClient(
UserAgent.of("android:me.ccrama.RedditSlide:v" + BuildConfig.VERSION_NAME));
final HashMap<String, String> accounts = new HashMap<>();
for (String s : Authentication.authentication.getStringSet("accounts",
new HashSet<String>())) {
if (s.contains(":")) {
accounts.put(s.split(":")[0], s.split(":")[1]);
} else {
accounts.put(s, "");
}
}
final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
if (accounts.containsKey(profileName)
&& !accounts.get(profileName)
.isEmpty()) {
token = accounts.get(profileName);
} else {
ArrayList<String> tokens =
new ArrayList<>(
Authentication.authentication
.getStringSet(
"tokens",
new HashSet<String>()));
int index = keys.indexOf(profileName);
if (keys.indexOf(profileName)
> tokens.size()) {
index -= 1;
}
token = tokens.get(
index);
}
Authentication.doVerify(token, reddit, true, mContext);
return reddit;
}
示例9: Authentication
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
public Authentication(Context context) {
Reddit.setDefaultErrorHandler(context);
if (NetworkUtil.isConnected(context)) {
hasDone = true;
httpAdapter = new OkHttpAdapter(Reddit.client, Protocol.HTTP_2);
isLoggedIn = false;
reddit = new RedditClient(
UserAgent.of("android:me.ccrama.RedditSlide:v" + BuildConfig.VERSION_NAME),
httpAdapter);
reddit.setRetryLimit(2);
if (BuildConfig.DEBUG) reddit.setLoggingMode(LoggingMode.ALWAYS);
didOnline = true;
new VerifyCredentials(context).execute();
} else {
isLoggedIn = Reddit.appRestart.getBoolean("loggedin", false);
name = Reddit.appRestart.getString("name", "");
if ((name.isEmpty() || !isLoggedIn) && !authentication.getString("lasttoken", "")
.isEmpty()) {
for (String s : Authentication.authentication.getStringSet("accounts",
new HashSet<String>())) {
if (s.contains(authentication.getString("lasttoken", ""))) {
name = (s.split(":")[0]);
break;
}
}
isLoggedIn = true;
}
}
}
示例10: getUserAgent
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
@Override
public UserAgent getUserAgent() {
return UserAgent.of(this.platform, this.packageName, this.version, this.redditUsername);
}
示例11: getUserAgent
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
@Bean
public UserAgent getUserAgent() {
return UserAgent.of("desktop", "org.sgs.stashbot", getStashbotVersion(), "StashThis");
}
示例12: testUserAgent
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
@Test
public void testUserAgent() {
UserAgent userAgent = SpringContext.getBean(UserAgent.class);
Assert.assertNotNull("Could not get bean from context!", userAgent);
Assert.assertEquals("Val not properly set by Spring!", "desktop:org.sgs.stashbot:0.1.1 (by /u/ArchiveThisBot)", userAgent.toString());
}
示例13: getUserAgent
import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
UserAgent getUserAgent();