我想在java中编写代码以获取用户所有来自Twitter的“关注用户ID”信息我已经搜索了很多并找到了使用twitter API的scribe库。我已经下载了scribe jar并包含在我的eclipse java项目中,我的问题是当我尝试运行以下代码时:
import java.util.Scanner;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class TwitterExample
{
private static final String PROTECTED_RESOURCE_URL = "http://api.twitter.com /1.1/account/verify_credentials.json";
public static void main(String[] args)
{
// If you choose to use a callback, "oauth_verifier" will be the return value by Twitter (request param)
OAuthService service = new ServiceBuilder()
.provider(TwitterApi.class)
.apiKey("6icbcAXyZx67r8uTAUM5Qw")
.apiSecret("SCCAdUUc6LXxiazxH3N0QfpNUvlUy84mZ2XZKiv39s")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== Twitter's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
request.addBodyParameter("status", "this is sparta! *");
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
我知道这段代码不是为了获取“跟随用户ID”信息,实际上这段代码在以下链接上可用作为scribe的可运行示例,在某些地方我必须填写我的密钥。
当我在代码上面运行时,我遇到以下错误:
=== Twitter的OAuth工作流程===
获取请求令牌... 线程“main”中的异常java.lang.NoClassDefFoundError:org / apache / commons / codec / binary / Base64 at org.scribe.services.HMACSha1SignatureService.doSign(HMACSha1SignatureService.java:47) at org.scribe.services.HMACSha1SignatureService.getSignature(HMACSha1SignatureService.java:33) at org.scribe.oauth.OAuth10aServiceImpl.getSignature(OAuth10aServiceImpl.java:122) 在org.scribe.oauth.OAuth10aServiceImpl.addOAuthParams(OAuth10aServiceImpl.java:63) at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:43) 在assignment.TwitterExample.main(TwitterExample.java:30) 引起:java.lang.ClassNotFoundException:org.apache.commons.codec.binary.Base64 在java.net.URLClassLoader $ 1.run(未知来源) 在java.net.URLClassLoader $ 1.run(未知来源) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher $ AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ......还有6个 请帮忙。