如何在python中使用api键从google plus中获取数据?

时间:2013-09-23 10:18:51

标签: python json python-2.7 google-api google-plus

* *当我发送请求时 -

f = urllib.urlopen(https://www.googleapis.com/plus/v1/people/103777531434977807649/activities/public?key=*************** )
json=f.read()
print json

它会返回一些像这样的东西,而不是必需的json

{
"kind": "plus#activityFeed",
 "etag": "\"seVFOlIgH91k2i-GrbizYfaw_AM/chWYjTdvKRLG9yxkeAfrCrofGHk\"",
 "nextPageToken": "CAIQ__________9_IAAoAA",
 "title": "Google+ List of Activities for Collection PUBLIC",
 "items": []
}

我必须做些什么才能得到正确的回应????

这是代码:     导入json

    f = urllib.urlopen('https://www.googleapis.com/plus/v1/people/'+id+'/activities    /public?key=*****************&maxResults=100')               
    s = f.read()                            
    f.close()              
    ss=json.loads(s)
            print ss 
            try:        
        nextpagetoken=str(ss['nextPageToken'])
        i=0
        str_current_datetime=str(datetime.now())
        gp_crawldate=str_current_datetime.split(" ")[0]
        gp_groupid=id
        db = MySQLdb.connect("localhost","root","****","googleplus" )
        cursor=db.cursor()

        while i<len(ss['items']):

            gp_kind=str(ss['items'][i]['kind'])
            gp_title=str(ss['items'][i]['title'].encode('utf8'))
            gp_published=str(ss['items'][i]['published'][0:10])
                            check=int(cool(str(ss['items'][i]['published'][0:19])))#this method is defined in the code 
            gp_activityid=str(ss['items'][i]['id'])
            gp_actorid=str(ss['items'][i]['actor']['id'])
            gp_verb=str(ss['items'][i]['verb'])
            gp_objecttype=str(ss['items'][i]['object']['objectType'])
            gp_originalcontent=str(ss['items'][i]['object']['content'].encode('utf8'))  
            gp_totalreplies=str(ss['items'][i]['object']['replies']['totalItems'])
            gp_totalplusone=str(ss['items'][i]['object']['plusoners']['totalItems'])
            gp_totalreshare=str(ss['items'][i]['object']['resharers']['totalItems'])
            #gp_geocode=str(ss['items'][i]['geocode'])
            #gp_placename=str(ss['items'][i]['placeName'])
            i=i+1

是g + api的任何变化???

1 个答案:

答案 0 :(得分:1)

您发布的回复是正确的回复。如果items字段是空列表,那么您要获取帖子的用户可能从未公开过任何内容。在这种情况下,我确认用户仅通过访问他们的个人资料就没有公开信息。