6
我试图连接到谷歌API。
这工作正常在我的终端,我在做:
curl https://www.googleapis.com/tasks/v1/users/@me/lists --header "Authorization: Bearer myAccessCode"
。
这工作正常,但现在我想要在一个C程序内。
为此,我有:
让https使用libcurl
CURL *curl;
char *header = "Authorization: Bearer myAccessCode";
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, header);
curl = curl_easy_init();
char *response = NULL;
curl_easy_setopt(curl, CURLOPT_URL, "https://www.googleapis.com/tasks/v1/users/@me/lists");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, httpsCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
但在这里我刚开始是一个需要登录的消息。 我不知道我在做什么错,是否有人看到我的失败?
我只是意识到,我提出:'curl_slist_append(报头,报头);'
代替:'头= curl_slist_append(头,头文件);'
所以头文件总是NULL,并且我做了没有头文件的get请求。
(我在上面的问题中编辑了它,所以代码有效,如果有人有类似的问题) – EarlOfEgo 2012-04-18 14:39:57
那么问题就已经解决了吗? – 2012-04-19 06:31:19
是的,但是我的声望点迫使我等了10个小时才回答自己的问题:-)所以我现在就做。 – EarlOfEgo 2012-04-19 10:21:53