Permalink
Browse files

Change googlereader to use auth instead of sid.

The Google Reader API changed to use auth over sid for authentication as well
as requiring certain header elements be present in the requests.  For more
information, see
https://groups.google.com/group/fougrapi/browse_thread/thread/e331f37f7f126c00/09b1db56ef7c1fdf
  • Loading branch information...
Seth Mason authored and akrennmair committed Jun 23, 2010
1 parent 2f704a5 commit 31933f2e60f2d99b08fd5108e63421997a900696
Showing with 18 additions and 16 deletions.
  1. +2 −2 include/google_api.h
  2. +16 −14 src/google_api.cpp
View
@@ -19,11 +19,11 @@ class googlereader_api : public remote_api {
private:
std::vector<std::string> get_tags(xmlNode * node);
std::string get_new_token();
std::string retrieve_sid();
std::string retrieve_auth();
std::string post_content(const std::string& url, const std::string& postdata);
bool star_article(const std::string& guid, bool star);
bool share_article(const std::string& guid, bool share);
std::string sid;
std::string auth;
};
class googlereader_urlreader : public urlreader {
View
@@ -29,9 +29,9 @@ googlereader_api::~googlereader_api() {
}
bool googlereader_api::authenticate() {
sid = retrieve_sid();
LOG(LOG_DEBUG, "googlereader_api::authenticate: SID = %s", sid.c_str());
return sid != "";
auth = retrieve_auth();
LOG(LOG_DEBUG, "googlereader_api::authenticate: Auth = %s", auth.c_str());
return auth != "";
}
static size_t my_write_data(void *buffer, size_t size, size_t nmemb, void *userp) {
@@ -40,12 +40,12 @@ static size_t my_write_data(void *buffer, size_t size, size_t nmemb, void *userp
return size * nmemb;
}
std::string googlereader_api::retrieve_sid() {
std::string googlereader_api::retrieve_auth() {
CURL * handle = curl_easy_init();
std::string postcontent = utils::strprintf("service=reader&Email=%s&Passwd=%s&source=%s/%s&continue=http://www.google.com/",
cfg->get_configvalue("googlereader-login").c_str(), cfg->get_configvalue("googlereader-password").c_str(), PROGRAM_NAME, PROGRAM_VERSION);
std::string result;
utils::set_common_curl_options(handle, cfg);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, my_write_data);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &result);
@@ -56,10 +56,10 @@ std::string googlereader_api::retrieve_sid() {
std::vector<std::string> lines = utils::tokenize(result);
for (std::vector<std::string>::iterator it=lines.begin();it!=lines.end();it++) {
LOG(LOG_DEBUG, "googlereader_api::retrieve_sid: line = %s", it->c_str());
if (it->substr(0,4)=="SID=") {
std::string sid = it->substr(4, it->length()-4);
return sid;
LOG(LOG_DEBUG, "googlereader_api::retrieve_auth: line = %s", it->c_str());
if (it->substr(0,5)=="Auth=") {
std::string auth = it->substr(5, it->length()-5);
return auth;
}
}
@@ -71,10 +71,9 @@ std::vector<tagged_feedurl> googlereader_api::get_subscribed_urls() {
CURL * handle = curl_easy_init();
std::string result;
std::string cookie = utils::strprintf("SID=%s;", sid.c_str());
configure_handle(handle);
utils::set_common_curl_options(handle, cfg);
curl_easy_setopt(handle, CURLOPT_COOKIE, cookie.c_str());
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, my_write_data);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &result);
curl_easy_setopt(handle, CURLOPT_URL, GREADER_SUBSCRIPTION_LIST);
@@ -153,8 +152,11 @@ std::vector<std::string> googlereader_api::get_tags(xmlNode * node) {
}
void googlereader_api::configure_handle(CURL * handle) {
std::string cookie = utils::strprintf("SID=%s;", sid.c_str());
curl_easy_setopt(handle, CURLOPT_COOKIE, cookie.c_str());
struct curl_slist *chunk = NULL;
std::string header = utils::strprintf("Authorization: GoogleLogin auth=%s", auth.c_str());
LOG(LOG_DEBUG, "googlereader_api::configure_handle header = %s result = %s", header.c_str());
chunk = curl_slist_append(chunk, header.c_str());
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, chunk);
}
bool googlereader_api::mark_all_read(const std::string& feedurl) {

0 comments on commit 31933f2

Please sign in to comment.