我为youTube api实现了OAuth ..
public class LocalServerReceiverRetriever {
private static final Logger logger = LoggerFactory
.getLogger(FileUploadController.class);
private static LocalServerReceiver localServerReceiver = null;
public static LocalServerReceiver getLocalServerReceiver(){
if(localServerReceiver == null){
localServerReceiver = new LocalServerReceiver.Builder().setPort(8081).build();
}else{
try {
localServerReceiver.stop();
} catch (IOException e) {
logger.error(e.getMessage() + e.getCause());
}
localServerReceiver = new LocalServerReceiver.Builder().setPort(8081).build();
}
return localServerReceiver ;
}
}
public static Credential authorize(List scopes,String credentialDatastore)抛出IOException {
// Load client secrets.
// more code....
// Build the local server and bind it to port 8081
LocalServerReceiver localReceiver = LocalServerReceiverRetriever.getLocalServerReceiver();
logger.debug("localReceiver set up to 8081");
// Authorize.
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}
在本地工作。逻辑上我将回调URL更改为http://localhost:8081/CallBack ..在本地工作正常,但当我使用公共IP部署到 AWS服务器时,它不起作用。。
显示已用于8081例外的地址,甚至不会重定向到Google身份验证页面。
答案 0 :(得分:0)
这仅仅意味着端口8081已被AWS上的某些其他服务占用。要么停止该服务,要么为您的应用程序选择8081以外的新端口。它会起作用。