twitter4j.Twitter.verifyCredentials()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中twitter4j.Twitter.verifyCredentials()方法的一些代码示例,展示了Twitter.verifyCredentials()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Twitter.verifyCredentials()方法的具体详情如下:
包路径:twitter4j.Twitter
类名称:Twitter
方法名:verifyCredentials

Twitter.verifyCredentials介绍

[英]Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status code and an error message if not. Use this method to test if supplied user credentials are valid.
[中]如果身份验证成功,则返回HTTP 200 OK响应代码和请求用户的表示;返回401状态代码,否则返回错误消息。使用此方法测试提供的用户凭据是否有效。

代码示例

代码示例来源:origin: jchampemont/WTFDYUM

@Override
public boolean verifyCredentials(final Principal principal) {
  boolean result = true;
  try {
    twitter(principal).verifyCredentials();
  } catch (final TwitterException e) {
    result = false;
  }
  return result;
}

代码示例来源:origin: org.twitter4j/twitter4j-async

@Override
  public void invoke(List<TwitterListener> listeners) throws TwitterException {
    User user = twitter.verifyCredentials();
    for (TwitterListener listener : listeners) {
      try {
        listener.verifiedCredentials(user);
      } catch (Exception e) {
        logger.warn("Exception at verifyCredentials", e);
      }
    }
  }
});

代码示例来源:origin: stackoverflow.com

Twitter twitter = TwitterFactory.getSingleton();
twitter.setOAuthConsumer("[consumer key]", "[consumer secret]");
RequestToken requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (null == accessToken) {
 System.out.println("Open the following URL and grant access to your account:");
 System.out.println(requestToken.getAuthorizationURL());
 System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
 String pin = br.readLine();
 try{
   if(pin.length() > 0){
    accessToken = twitter.getOAuthAccessToken(requestToken, pin);
   }else{
    accessToken = twitter.getOAuthAccessToken();
   }
 } catch (TwitterException te) {
  if(401 == te.getStatusCode()){
   System.out.println("Unable to get the access token.");
  }else{
   te.printStackTrace();
  }
 }
}
//persist to the accessToken for future reference.
storeAccessToken(twitter.verifyCredentials().getId() , accessToken);
Status status = twitter.updateStatus(args[0]);
System.out.println("Successfully updated the status to [" + status.getText() + "].");
System.exit(0);

代码示例来源:origin: stackoverflow.com

Twitter twitter = TwitterFactory.getSingleton();
twitter.setOAuthConsumer("[consumer key]", "[consumer secret]");
RequestToken requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (null == accessToken) {
 System.out.println("Open the following URL and grant access to your account:");
 System.out.println(requestToken.getAuthorizationURL());
 System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
 String pin = br.readLine();
 try{
   if(pin.length() > 0){
    accessToken = twitter.getOAuthAccessToken(requestToken, pin);
   }else{
    accessToken = twitter.getOAuthAccessToken();
   }
 } catch (TwitterException te) {
  if(401 == te.getStatusCode()){
   System.out.println("Unable to get the access token.");
  }else{
   te.printStackTrace();
  }
 }
}
//persist to the accessToken for future reference.
storeAccessToken(twitter.verifyCredentials().getId() , accessToken);
Status status = twitter.updateStatus(args[0]);
System.out.println("Successfully updated the status to [" + status.getText() + "].");
System.exit(0);

代码示例来源:origin: org.sakaiproject.profile2/profile2-impl

return twitter.verifyCredentials().getScreenName();
} catch (TwitterException e) {
  log.error("Error retrieving Twitter credentials: " + e.getClass() + ": " + e.getMessage());

代码示例来源:origin: picketlink/picketlink

principal = new TwitterPrincipal(twitter.verifyCredentials());

代码示例来源:origin: stackoverflow.com

TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
twitter.verifyCredentials();

代码示例来源:origin: stackoverflow.com

User user = twitter.verifyCredentials();
List<Status> statuses = twitter.getMentionsTimeline();
System.out.println("Showing @" + user.getScreenName() + "'s mentions.");

代码示例来源:origin: stackoverflow.com

User user = mTwitter.verifyCredentials();
mSession.storeAccessToken(mAccessToken, user.getName());
UserName = user.getName();

代码示例来源:origin: stackoverflow.com

User user = mTwitter.verifyCredentials();

代码示例来源:origin: org.apache.camel/camel-twitter

private void verifyCredentials(ResultBuilder builder, Map<String, Object> parameters) throws Exception {
    try {
      TwitterConfiguration configuration = setProperties(new TwitterConfiguration(), parameters);
      Twitter twitter = configuration.getTwitter();

      twitter.verifyCredentials();
    } catch (TwitterException e) {
      // verifyCredentials throws TwitterException when Twitter service or
      // network is unavailable or if supplied credential is wrong
      ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getErrorMessage())
        .detail("twitter_error_code", e.getErrorCode())
        .detail("twitter_status_code", e.getStatusCode())
        .detail("twitter_exception_code", e.getExceptionCode())
        .detail("twitter_exception_message", e.getMessage())
        .detail("twitter_exception_caused-by-network-issue", e.isCausedByNetworkIssue())
        .detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName())
        .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e);

      // For a complete list of error codes see:
      //   https://dev.twitter.com/overview/api/response-codes
      if (e.getErrorCode() == 89) {
        errorBuilder.parameterKey("accessToken");
      }

      builder.error(errorBuilder.build());
    }
  }
}

相关文章