简体   繁体   中英

how to fetch data from google plus using api key in python?

* *When i send a request like --

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

it returns some thing like this not the required json

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

what i have to do to get the right response????

this is the code: import 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

is the any change in g+api???

The response you posted is a correct response. If the items field is an empty list, then the user that you are fetching the posts for has probably never posted anything publicly. In this case, I confirmed that the user has no public posts simply by visiting their profile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM