def get_gmail_access_token(): session = bottle.request.query["session"] saved_request_token = sessions[session] del sessions[session] # Session is no longer needed at this point (unless user refreshes browser) # TODO: If there is no longer a session (user refreshes page), just return the normal page and rely on the cached results showing up request_token = gdata.gauth.AuthorizeRequestToken(saved_request_token, "?" + bottle.request.query_string) client = gdata.contacts.client.ContactsClient(source="PGP key finder") access_token = client.GetAccessToken(request_token) client.auth_token = access_token feed = client.get_contacts() addresses = [] # Loop over "result pages" while feed: for entry in feed.entry: addresses += ['"%s"' % x.address for x in entry.email] try: feed = client.get_next(feed) except AttributeError: # TODO: How are you actually supposed to know when it's done? break # Insert some code that searches for the found keys return keysearch_html.replace( "DO NOT CHANGE THIS LINE -->", '--> <script type="text/javascript">\nfunction lookupFromServer() { if(document.referrer.indexOf("accounts.google.com") >-1 ) { lookupAddresses([%s]); }}\nlookupFromServer();\n</script>' % (",".join(addresses)), )
def fetch_friends(self, user): """ fetches the friends from g+ using the information on django-social-auth models user is an instance of UserSocialAuth. Notice that g+ contact api should be enabled in google cloud console and social auth scope has been set this way in settings.py GOOGLE_OAUTH_EXTRA_SCOPE = ['https://www.google.com/m8/feeds/'] Returns: collection of friend data dicts fetched from google contact api """ if USING_ALLAUTH: social_app = SocialApp.objects.get_current('google') oauth_token = SocialToken.objects.get(account=user, app=social_app).token else: social_auth_backend = GoogleOAuth2Backend() # Get the access_token tokens = social_auth_backend.tokens(user) oauth_token = tokens['access_token'] credentials = gdata.gauth.OAuth2Token( client_id=settings.GOOGLE_OAUTH2_CLIENT_ID, client_secret=settings.GOOGLE_OAUTH2_CLIENT_SECRET, scope='https://www.google.com/m8/feeds/', user_agent='gdata', access_token=oauth_token ) client = gdata.contacts.client.ContactsClient() credentials.authorize(client) contacts = client.get_contacts() data = feedparser.parse(contacts.to_string())['entries'] return data
def fetch_friends(self, user): """ fetches the friends from g+ using the information on django-social-auth models user is an instance of UserSocialAuth. Notice that g+ contact api should be enabled in google cloud console and social auth scope has been set this way in settings.py GOOGLE_OAUTH_EXTRA_SCOPE = ['https://www.google.com/m8/feeds/'] Returns: collection of friend data dicts fetched from google contact api """ if USING_ALLAUTH: social_app = SocialApp.objects.get_current('google') oauth_token = SocialToken.objects.get(account=user, app=social_app).token else: social_auth_backend = GoogleOAuth2Backend() # Get the access_token tokens = social_auth_backend.tokens(user) oauth_token = tokens['access_token'] credentials = gdata.gauth.OAuth2Token( client_id=settings.GOOGLE_OAUTH2_CLIENT_ID, client_secret=settings.GOOGLE_OAUTH2_CLIENT_SECRET, scope='https://www.google.com/m8/feeds/', user_agent='gdata', access_token=oauth_token) client = gdata.contacts.client.ContactsClient() credentials.authorize(client) contacts = client.get_contacts() data = feedparser.parse(contacts.to_string())['entries'] return data
for amigo in friends: if entry.title.text == amigo["name"]: print "Mudando foto: "+str(amigo["uid"]) + " " + (amigo["name"].encode("utf-8")).decode("utf-8") profile_pic = "https://graph.facebook.com/"+str(amigo["uid"])+"/picture?type=large" try: urlretrieve(profile_pic, str(amigo["name"].encode("utf-8")).decode("utf-8")+".jpg") except: print "Erro ao tentar modificar a foto de " + (amigo["name"].encode("utf-8")).decode("utf-8") continue client.change_photo(str(amigo["name"].encode("utf-8")).decode("utf-8")+".jpg",entry,"image/jpeg") cont += 1 os.remove(str(amigo["name"].encode("utf-8")).decode("utf-8")+".jpg") pegou = 0 break if pegou == 1: naoPegou.append(entry.title.text) print "Foram pegos " + str(cont) + " contatos.\n" for nome in naoPegou: print nome print datetime.now() fbconsole.AUTH_SCOPE = ['publish_stream','read_stream','email'] fbconsole.authenticate() usr = raw_input() passwd = raw_input() client = gdata.contacts.client.ContactsClient() client.client_login(usr, passwd, "myscript") qry = gdata.contacts.client.ContactsQuery(max_results=3000) feed = client.get_contacts(query=qry) getEmail() print datetime.now()