2015-07-19 152 views
1

我正在使用Windovs的C++编写应用程序以使用云服务Amazon。我需要在网站上获得授权才能使用特定数据,并且我想获得Access令牌。问题是我想要的,我没有使用浏览器获得授权,但我不明白如何。我使用卷曲的项目,并发送类似如下的要求:当我得到响应我有一个HTML页面的授权文件的副本在没有浏览器的情况下登录亚马逊

int main(void) { 
CURL *curl; 
CURLcode res; 
struct curl_slist *list = NULL; 
FILE *Response = fopen("Response.txt", "wb+"); 
curl = curl_easy_init(); 
if (curl) { 
    curl_easy_setopt(curl, CURLOPT_URL, "https://www.amazon.com/ap/oa?client_id=%MY CLIENT ID%scope=clouddrive:read_all&response_type=token&redirect_uri=http://localhost"); 

    list = curl_slist_append(list, "Accept: text/html"); 
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); 
    curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); 
    curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); 
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, SaveData); 
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, Response); 
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); 

    /* Perform the request, res will get the return code */ 
    res = curl_easy_perform(curl); 

    /* Check for errors */ 
    if (res != CURLE_OK) 
     fprintf(Response, "curl_easy_perform() failed: %s\n", 
     curl_easy_strerror(res)); 


    curl_slist_free_all(list); 
    /* always cleanup */ 
    curl_easy_cleanup(curl); 
} 

。/下面是答案的一部分/

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> 
 
    <html xmlns=\"http://www.w3.org/1999/xhtml\"> 
 
    
 
<head> 
 
<script type='text/javascript'>var ue_t0=ue_t0||+new Date();</script> 
 
<script type='text/javascript'> 
 
var ue_csm = window, 
 
    ue_hob = +new Date();

如果我不能使用的浏览器,而我可以用Web浏览器(无边框)打开一个小窗口,并接收来自服务器的数据(访问令牌)。文档中没有任何内容(Amazon文档)。

回答

0

如果你想让你的应用程序“谈”到AWS,你应该使用他们的API,而不是Web控制台。 API请求是无状态的并且signed with credentials,并且不依赖于Web控制台等身份验证会话。

他们有许多流行的语言官方的SDK,而不是C++,很遗憾。所以,除非你找到某个地方,否则你将不得不实现你自己的客户端,但它都是基于HTTP(S)的。

另一件事值得一提的是,每一个产品都有一个单独的和独立的API(EC2S3RDS等)。据我所知,你不会找到所有AWS产品的全功能API。文档也可能有点稀疏,但大多数产品都被覆盖。

祝你好运。 ;)

相关问题