【发布时间】:2015-06-12 10:13:47
【问题描述】:
我想从我的应用程序中授权用户,我正在关注互联网上的一些示例 (http://www.programcreek.com/java-api-examples/index.php?api=org.scribe.model.Token):
public static void auth() throws IOException, FlickrException {
Properties properties;
InputStream in=null;
try {
in=AuthExample.class.getResourceAsStream("/setup.properties");
properties=new Properties();
properties.load(in);
}
finally {
IOUtilities.close(in);
}
Flickr flickr=new Flickr(properties.getProperty("apiKey"),properties.getProperty("secret"),new REST());
Flickr.debugStream=false;
AuthInterface authInterface=flickr.getAuthInterface();
Scanner scanner=new Scanner(System.in);
Token token=authInterface.getRequestToken();
System.out.println("token: " + token);
String url=authInterface.getAuthorizationUrl(token,Permission.READ);
System.out.println("Follow this URL to authorise yourself on Flickr");
System.out.println(url);
System.out.println("Paste in the token it gives you:");
System.out.print(">>");
String tokenKey=scanner.nextLine();
Token requestToken=authInterface.getAccessToken(token,new Verifier(tokenKey));
System.out.println("Authentication success");
Auth auth=authInterface.checkToken(requestToken);
System.out.println("Token: " + requestToken.getToken());
System.out.println("nsid: " + auth.getUser().getId());
System.out.println("Realname: " + auth.getUser().getRealName());
System.out.println("Username: " + auth.getUser().getUsername());
System.out.println("Permission: " + auth.getPermission().getType());
}
我正在使用 webview、scribe 和 Flickr4Java 作为运行 URL,它们提供代码、身份验证和 Web 视图向我显示代码,它我必须传递给我的应用程序,但我不明白如何从 webview 检索此 code,并传递给 tokenKey。
I am added onpageFinished and print URL which me give:
06-12 13:03:55.266 E/NEW﹕ uri is: https://m.flickr.com/services/oauth/authorize?oauth_token=72157654039925698-81abc00d035f5da0&perms=write
06-12 13:03:55.601 W/BindingManager﹕ Cannot call determinedVisibility() - never saw a connection for the pid: 4581
06-12 13:03:56.166 E/NEW﹕ uri is: https://m.flickr.com/#/services/oauth/authorize/_QM_oauth_token_IS_72157654039925698-81abc00d035f5da0_AND_perms_IS_write
06-12 13:03:56.476 W/BindingManager﹕ Cannot call determinedVisibility() - never saw a connection for the pid: 4581
06-12 13:03:56.476 E/NEW﹕ uri is: https://m.flickr.com/#/services/oauth/authorize/_QM_oauth_token_IS_72157654039925698-81abc00d035f5da0_AND_perms_IS_write
06-12 13:04:00.411 W/BindingManager﹕ Cannot call determinedVisibility() - never saw a connection for the pid: 4581
06-12 13:04:00.416 E/NEW﹕ uri is: https://m.flickr.com/#/#
【问题讨论】: