当前位置: 首页>>代码示例>>Java>>正文


Java UserAgent类代码示例

本文整理汇总了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
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:24,代码来源:ReddigramBot.java

示例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);
}
 
开发者ID:jorgegil96,项目名称:JRAW-Android-Sample,代码行数:29,代码来源:MainActivity.java

示例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<>();
}
 
开发者ID:nikmanG,项目名称:DailyProgrammer,代码行数:12,代码来源:ScraperBot.java

示例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();
    }
}
 
开发者ID:dessalines,项目名称:flowchat,代码行数:16,代码来源:RedditImporter.java

示例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);
    }
 
开发者ID:vitalijzad,项目名称:java-rss-for-reddit,代码行数:10,代码来源:RedditSubmitter.java

示例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);
}
 
开发者ID:JotraN,项目名称:Reader,代码行数:9,代码来源:JrawReaderHelper.java

示例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);
}
 
开发者ID:ashwinswaroop,项目名称:YouTubeBot,代码行数:12,代码来源:Authenticator.java

示例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;
}
 
开发者ID:ccrama,项目名称:Slide,代码行数:38,代码来源:CommentAdapter.java

示例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;
        }
    }


}
 
开发者ID:ccrama,项目名称:Slide,代码行数:33,代码来源:Authentication.java

示例10: getUserAgent

import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
@Override
public UserAgent getUserAgent() {
    return UserAgent.of(this.platform, this.packageName, this.version, this.redditUsername);
}
 
开发者ID:AlbinoDrought,项目名称:party-reader,代码行数:5,代码来源:ResFactory.java

示例11: getUserAgent

import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
@Bean
public UserAgent getUserAgent() {
    return UserAgent.of("desktop", "org.sgs.stashbot", getStashbotVersion(), "StashThis");
}
 
开发者ID:sgskinner,项目名称:StashThisBot,代码行数:5,代码来源:StashThisConfiguration.java

示例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());
}
 
开发者ID:sgskinner,项目名称:StashThisBot,代码行数:7,代码来源:AppBootstrapTest.java

示例13: getUserAgent

import net.dean.jraw.http.UserAgent; //导入依赖的package包/类
UserAgent getUserAgent(); 
开发者ID:AlbinoDrought,项目名称:party-reader,代码行数:2,代码来源:UserAgentFactory.java


注:本文中的net.dean.jraw.http.UserAgent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。