سؤال

هل يحتوي Google Reader على واجهة برمجة تطبيقات، وإذا كان الأمر كذلك، فكيف يمكنني الحصول على عدد المشاركات غير المقروءة لمستخدم معين مع معرفة اسم المستخدم وكلمة المرور الخاصة به؟

هل كانت مفيدة؟

المحلول

سيعطيك عنوان URL هذا عددًا من المشاركات غير المقروءة لكل خلاصة.يمكنك بعد ذلك التكرار على الخلاصات وتلخيص الأعداد.

http://www.google.com/reader/api/0/unread-count?all=true

فيما يلي مثال مبسط في لغة بايثون... يُترك تحليل ملف xml/json وجمع الأعداد كتمرين للقارئ:

import urllib
import urllib2

username = 'username@gmail.com'
password = '******'

# Authenticate to obtain SID
auth_url = 'https://www.google.com/accounts/ClientLogin'
auth_req_data = urllib.urlencode({'Email': username,
                                  'Passwd': password,
                                  'service': 'reader'})
auth_req = urllib2.Request(auth_url, data=auth_req_data)
auth_resp = urllib2.urlopen(auth_req)
auth_resp_content = auth_resp.read()
auth_resp_dict = dict(x.split('=') for x in auth_resp_content.split('\n') if x)
auth_token = auth_resp_dict["Auth"]

# Create a cookie in the header using the SID 
header = {}
header['Authorization'] = 'GoogleLogin auth=%s' % auth_token

reader_base_url = 'http://www.google.com/reader/api/0/unread-count?%s'
reader_req_data = urllib.urlencode({'all': 'true',
                                    'output': 'xml'})
reader_url = reader_base_url % (reader_req_data)
reader_req = urllib2.Request(reader_url, None, header)
reader_resp = urllib2.urlopen(reader_req)
reader_resp_content = reader_resp.read()

print reader_resp_content

وبعض الروابط الإضافية حول الموضوع:

نصائح أخرى

إنها هناك.لا يزال في مرحلة تجريبية بالرغم من ذلك.

هنا تحديث ل هذه الإجابة

import urllib
import urllib2

username = 'username@gmail.com'
password = '******'

# Authenticate to obtain Auth
auth_url = 'https://www.google.com/accounts/ClientLogin'
#auth_req_data = urllib.urlencode({'Email': username,
#                                  'Passwd': password})
auth_req_data = urllib.urlencode({'Email': username,
                                  'Passwd': password,
                                  'service': 'reader'})
auth_req = urllib2.Request(auth_url, data=auth_req_data)
auth_resp = urllib2.urlopen(auth_req)
auth_resp_content = auth_resp.read()
auth_resp_dict = dict(x.split('=') for x in auth_resp_content.split('\n') if x)
# SID = auth_resp_dict["SID"]
AUTH = auth_resp_dict["Auth"]

# Create a cookie in the header using the Auth
header = {}
#header['Cookie'] = 'Name=SID;SID=%s;Domain=.google.com;Path=/;Expires=160000000000' % SID
header['Authorization'] = 'GoogleLogin auth=%s' % AUTH

reader_base_url = 'http://www.google.com/reader/api/0/unread-count?%s'
reader_req_data = urllib.urlencode({'all': 'true',
                                    'output': 'xml'})
reader_url = reader_base_url % (reader_req_data)
reader_req = urllib2.Request(reader_url, None, header)
reader_resp = urllib2.urlopen(reader_req)
reader_resp_content = reader_resp.read()

print reader_resp_content

قام Google Reader بإزالة مصادقة SID في يونيو 2010 تقريبًا (على ما أظن)، واستخدام مصادقة جديدة من ClientLogin هي الطريقة الجديدة وهي أبسط قليلاً (الرأس أقصر).سيكون عليك أن تضيف service في بيانات الطلب Auth, ، لاحظت لا Auth عاد إذا لم ترسل service=reader.

يمكنك قراءة المزيد حول تغيير طريقة المصادقة في هذا الموضوع.

في واجهة برمجة التطبيقات المنشورة في [1]، يجب أن يكون حقل "الرمز المميز" هو "T"

[1] http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top