Пример #1
0
 /** {@inheritDoc} */
 public AccessToken getOAuthAccessToken() throws TwitterException {
   ensureTokenIsAvailable();
   if (oauthToken instanceof AccessToken) {
     return (AccessToken) oauthToken;
   }
   oauthToken = new AccessToken(http.post(conf.getOAuthAccessTokenURL(), this));
   return (AccessToken) oauthToken;
 }
Пример #2
0
 /** {@inheritDoc} */
 public RequestToken getOAuthRequestToken(String callbackURL) throws TwitterException {
   HttpParameter[] params =
       null != callbackURL
           ? new HttpParameter[] {new HttpParameter("oauth_callback", callbackURL)}
           : new HttpParameter[0];
   oauthToken = new RequestToken(http.post(conf.getOAuthRequestTokenURL(), params, this), this);
   return (RequestToken) oauthToken;
 }
Пример #3
0
 /** {@inheritDoc} */
 public AccessToken getOAuthAccessToken(String oauthVerifier) throws TwitterException {
   ensureTokenIsAvailable();
   oauthToken =
       new AccessToken(
           http.post(
               conf.getOAuthAccessTokenURL(),
               new HttpParameter[] {new HttpParameter("oauth_verifier", oauthVerifier)},
               this));
   return (AccessToken) oauthToken;
 }
Пример #4
0
 InputStream getSiteStream(boolean withFollowings, long[] follow) throws TwitterException {
   ensureOAuthEnabled();
   return http.post(
           conf.getSiteStreamBaseURL() + "site.json",
           new HttpParameter[] {
             new HttpParameter("with", withFollowings ? "followings" : "user"),
             new HttpParameter("follow", T4JInternalStringUtil.join(follow))
           },
           auth)
       .asStream();
 }
Пример #5
0
 /** {@inheritDoc} */
 public StatusStream getFilterStream(FilterQuery query) throws TwitterException {
   ensureAuthorizationEnabled();
   try {
     return new StatusStreamImpl(
         getDispatcher(),
         http.post(
             conf.getStreamBaseURL() + "statuses/filter.json", query.asHttpParameterArray(), auth),
         conf);
   } catch (IOException e) {
     throw new TwitterException(e);
   }
 }
Пример #6
0
 /** {@inheritDoc} */
 public StatusStream getRetweetStream() throws TwitterException {
   ensureAuthorizationEnabled();
   try {
     return new StatusStreamImpl(
         getDispatcher(),
         http.post(
             conf.getStreamBaseURL() + "statuses/retweet.json", new HttpParameter[] {}, auth),
         conf);
   } catch (IOException e) {
     throw new TwitterException(e);
   }
 }
Пример #7
0
 private StatusStream getCountStream(String relativeUrl, int count) throws TwitterException {
   ensureAuthorizationEnabled();
   try {
     return new StatusStreamImpl(
         getDispatcher(),
         http.post(
             conf.getStreamBaseURL() + relativeUrl,
             new HttpParameter[] {new HttpParameter("count", String.valueOf(count))},
             auth),
         conf);
   } catch (IOException e) {
     throw new TwitterException(e);
   }
 }
Пример #8
0
  public String upload() throws TwitterException {
    preUpload();
    if (this.postParameter == null) {
      throw new AssertionError("Incomplete implementation. postParameter is not set.");
    }
    if (this.uploadUrl == null) {
      throw new AssertionError("Incomplete implementation. uploadUrl is not set.");
    }

    httpResponse = client.post(uploadUrl, postParameter, headers);

    String mediaUrl = postUpload();
    logger.debug("uploaded url [" + mediaUrl + "]");

    return mediaUrl;
  }
Пример #9
0
 /**
  * Retrieves an access token associated with the supplied screen name and password using xAuth.
  * <br>
  * In order to get access acquire AccessToken using xAuth, you must apply by sending an email to
  * [email protected] — all other applications will receive an HTTP 401 error. Web-based applications
  * will not be granted access, except on a temporary basis for when they are converting from
  * basic-authentication support to full OAuth support.<br>
  * Storage of Twitter usernames and passwords is forbidden. By using xAuth, you are required to
  * store only access tokens and access token secrets. If the access token expires or is expunged
  * by a user, you must ask for their login and password again before exchanging the credentials
  * for an access token.
  *
  * @param screenName the screen name
  * @param password the password
  * @return access token associated with the supplied request token.
  * @throws TwitterException when Twitter service or network is unavailable, or the user has not
  *     authorized
  * @see <a href="http://dev.twitter.com/pages/oauth_faq">OAuth FAQ | dev.twitter.com - How long
  *     does an access token last?</a>
  * @see <a
  *     href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-oauth-access_token-for-xAuth">Twitter
  *     REST API Method: oauth access_token for xAuth</a>
  * @since Twitter 2.1.1
  */
 public AccessToken getOAuthAccessToken(String screenName, String password)
     throws TwitterException {
   try {
     oauthToken =
         new AccessToken(
             http.post(
                 conf.getOAuthAccessTokenURL(),
                 new HttpParameter[] {
                   new HttpParameter("x_auth_username", screenName),
                   new HttpParameter("x_auth_password", password),
                   new HttpParameter("x_auth_mode", "client_auth")
                 },
                 this));
     return (AccessToken) oauthToken;
   } catch (TwitterException te) {
     throw new TwitterException(
         "The screen name / password combination seems to be invalid.", te, te.getStatusCode());
   }
 }
Пример #10
0
 /** {@inheritDoc} */
 public UserStream getUserStream(String[] track) throws TwitterException {
   ensureAuthorizationEnabled();
   try {
     List<HttpParameter> params = new ArrayList<HttpParameter>();
     if (conf.isUserStreamRepliesAllEnabled()) {
       params.add(new HttpParameter("replies", "all"));
     }
     if (null != track) {
       params.add(new HttpParameter("track", T4JInternalStringUtil.join(track)));
     }
     return new UserStreamImpl(
         getDispatcher(),
         http.post(
             conf.getUserStreamBaseURL() + "user.json",
             params.toArray(new HttpParameter[params.size()]),
             auth),
         conf);
   } catch (IOException e) {
     throw new TwitterException(e);
   }
 }
Пример #11
0
 private static JSONObject getJSONObjectFromPostURL(String url, Configuration conf)
     throws Exception {
   HttpClientWrapper http = new HttpClientWrapper(conf);
   return http.post(url).asJSONObject();
 }