def getcontacts(self, start=0, page=25, group=None): contacts = [] profile = self.account.get("profile", {}) accounts = profile.get("accounts", [{}]) userdomain = "default" # google domains can have two contacts lists, the users and the domains # shared contacts. # shared contacts are only available in paid-for google domain accounts # and do not show the users full contacts list. I also did not find # docs on how to detect whether shared contacts is available or not, # so we will bypass this and simply use the users contacts list. # if accounts[0].get('domain') == 'googleapps.com': # # set the domain so we get the shared contacts # userdomain = accounts[0].get('userid').split('@')[-1] url = ( "http://www.google.com/m8/feeds/contacts/%s/full?v=1&orderby=lastmodified&sortorder=descending&max-results=%d" % (userdomain, page) ) method = "GET" if start > 0: url = url + "&start-index=%d" % (start,) if group: gid = self.getgroup_id(group) if not gid: error = {"provider": domain, "message": "Group '%s' not available" % group} return None, error url = url + "&group=%s" % (gid,) # itemsPerPage, startIndex, totalResults client = oauth.Client(self.consumer, self.oauth_token) resp, content = client.request(url, method) if int(resp.status) != 200: error = {"provider": domain, "message": content, "status": int(resp.status)} return None, error feed = gdata.contacts.ContactsFeedFromString(content) for entry in feed.entry: # print entry.group_membership_info if entry.email: p = {"displayName": entry.title.text, "emails": []} for email in entry.email: p["emails"].append({"value": email.address, "primary": email.primary}) if not p["displayName"]: p["displayName"] = email.address contacts.append(p) result = { "entry": contacts, "itemsPerPage": feed.items_per_page.text, "startIndex": feed.start_index.text, "totalResults": feed.total_results.text, } return result, None
def GetGroupContacts(self,groupid): try: query = gdata.contacts.service.ContactsQuery() query.group = groupid feed = self.client.GetContactsFeed(query.ToUri()) #logging.info('groupcontactsfeed' + str(feed)) contacts = [] for entry in feed.entry: contacts.append(GetContactUserInfo(entry)) return contacts except gdata.service.RequestError, request_error: logging.info('GetGroupContacts failed. Likely due to not being logged in. user: ' + users.get_current_user().nickname()) return None
def getcontacts(self, start=0, page=25, group=None): contacts = [] profile = self.account.get('profile', {}) accounts = profile.get('accounts', [{}]) userdomain = 'default' if accounts[0].get('domain') == 'googleapps.com': userdomain = accounts[0].get('userid').split('@')[-1] url = 'http://www.google.com/m8/feeds/contacts/%s/full?v=1&max-results=%d' % (userdomain, page,) method = 'GET' if start > 0: url = url + "&start-index=%d" % (start,) if group: gid = self.getgroup_id(group) if not gid: error={"provider": domain, "message": "Group '%s' not available" % group, } return None, error url = url + "&group=%s" % (gid,) # itemsPerPage, startIndex, totalResults client = oauth.Client(self.consumer, self.oauth_token) resp, content = client.request(url, method) if int(resp.status) != 200: error={"provider": domain, "message": content, "status": int(resp.status) } return None, error feed = gdata.contacts.ContactsFeedFromString(content) for entry in feed.entry: #print entry.group_membership_info p = { 'displayName': entry.title.text, } if entry.email: email = entry.email[0] p['emails'] = [{'value': email.address, 'primary': email.primary}] if not p['displayName']: p['displayName'] = email.address contacts.append(p) result = { 'entry': contacts, 'itemsPerPage': feed.items_per_page.text, 'startIndex': feed.start_index.text, 'totalResults': feed.total_results.text, } return result, None
def GetGroupContacts(self, groupid): try: query = gdata.contacts.service.ContactsQuery() query.group = groupid feed = self.client.GetContactsFeed(query.ToUri()) #logging.info('groupcontactsfeed' + str(feed)) contacts = [] for entry in feed.entry: contacts.append(GetContactUserInfo(entry)) return contacts except gdata.service.RequestError, request_error: logging.info( 'GetGroupContacts failed. Likely due to not being logged in. user: ' + users.get_current_user().nickname()) return None
def process_feed(feed): contacts = [] for entry in feed.entry: email_address = None for email in entry.email: if email.primary and email.primary == 'true': email_address = email.address break if email_address: contacts.append({ 'name': entry.name.full_name.text if entry.name else '', 'email': email_address }) return contacts
def processJson(self, method, user, req, resp, args, obj): gd_client = gdata.contacts.service.ContactsService() auth=AuthToken.all().filter('user ='******'http://freefallsocial.appspot.com/contacts/auth' scope = 'http://www.google.com/m8/feeds/' secure = False session = True gd_client = gdata.contacts.service.ContactsService() authSubLogin = gd_client.GenerateAuthSubURL(next, scope, secure, session) return [False, str(authSubLogin)] logging.debug('token: '+str(auth.token)); gd_client.SetAuthSubToken(auth.token) contacts=[] # feed = gd_client.GetContactsFeed() query = gdata.contacts.service.ContactsQuery() query.max_results=1000 feed = gd_client.GetContactsFeed(query.ToUri()) logging.debug('contacts #:'+str(len(feed.entry))) for i, entry in enumerate(feed.entry): # logging.debug('entry: '+str(dir(entry))) contact={} match=False if entry.title: contact['title']=entry.title.text if entry.email: for email in entry.email: if email.address and '@' in email.address and email.address.split('@')[1]=='gmail.com': contact['email']=email.address match=True if match: try: img = gd_client.GetPhoto(entry) if img: contact['image']='data:image/jpg;base64,'+base64.b64encode(img) else: contact['image']=None except Exception, e: logging.error('Error fetching photo: '+str(e)) contacts.append(contact) else: for email in entry.email: logging.debug('Rejecting '+str(email.address));
def ListAllContacts(self): """Retrieves a list of contacts and displays name and primary email.""" feed = self.gd_client.GetContactsFeed() contacts = [] while feed: for f in feed.entry: for e in f.email: if f.title.text: contacts.append({ f.title.text:e.address }) else: contacts.append({ e.address:e.address }) next = feed.GetNextLink() feed = None if next: feed = self.gd_client.GetContactsFeed(next.href) return contacts
def processContext(self, method, user, req, resp, args, context): gd_client = gdata.contacts.service.ContactsService() token=req.get('token') logging.debug('token: '+str(token)) if token and token!='': gd_client.SetAuthSubToken(token) gd_client.UpgradeToSessionToken() token=gd_client.GetAuthSubToken() a=AuthToken(user=user, token=token) a.save() contacts=[] # feed = gd_client.GetContactsFeed() query = gdata.contacts.service.ContactsQuery() query.max_results=1000 feed = gd_client.GetContactsFeed(query.ToUri()) logging.debug('contacts #:'+str(len(feed.entry))) for i, entry in enumerate(feed.entry): # logging.debug('entry: '+str(dir(entry))) contact={} match=False if entry.title: contact['title']=entry.title.text if entry.email: for email in entry.email: if email.address and '@' in email.address and email.address.split('@')[1]=='gmail.com': contact['email']=email.address match=True if match: try: img = gd_client.GetPhoto(entry) if img: contact['image']='data:image/jpg;base64,'+base64.b64encode(img) else: contact['image']=None except Exception, e: logging.error('Error fetching photo: '+str(e)) contacts.append(contact) else: for email in entry.email: logging.debug('Rejecting '+str(email.address));
def get_all_contacts(): global inited,contacts,gd_client,read_only,limit_delete # TODO: 首选使用AuthSub proxy authentication gd_client = gdata.contacts.service.ContactsService() gd_client.email = raw_input('请输入Gmail邮箱:').strip() # gd_client.password = raw_input('请输入%s的密码:'%gd_client.email).strip() if os.isatty(sys.stdin.fileno()): gd_client.password = getpass.getpass(prompt='请输入%s的密码:'%gd_client.email).strip() else: # print '请输入%s的密码:'%gd_client.email # gd_client.password = sys.stdin.readline().rstrip() gd_client.password = raw_input('请输入%s的密码:'%gd_client.email).strip() # gd_client.source = 'exampleCo-exampleApp-1' gd_client.ProgrammaticLogin() query = gdata.contacts.service.ContactsQuery() # query.orderby = 'title' # query['sortorder'] = 'ascending' query.max_results=10000 # feed = gd_client.GetContactsFeed() feed = gd_client.GetContactsFeed(query.ToUri()) for i, entry in enumerate(feed.entry): contacts.append(entry) inited = True
def getcontacts(self, start=0, page=25, group=None): contacts = [] profile = self.account.get('profile', {}) accounts = profile.get('accounts', [{}]) userdomain = 'default' # google domains can have two contacts lists, the users and the domains # shared contacts. # shared contacts are only available in paid-for google domain accounts # and do not show the users full contacts list. I also did not find # docs on how to detect whether shared contacts is available or not, # so we will bypass this and simply use the users contacts list. #if accounts[0].get('domain') == 'googleapps.com': # # set the domain so we get the shared contacts # userdomain = accounts[0].get('userid').split('@')[-1] url = 'http://www.google.com/m8/feeds/contacts/%s/full?v=1&orderby=lastmodified&sortorder=descending&max-results=%d' % (userdomain, page,) method = 'GET' if start > 0: url = url + "&start-index=%d" % (start,) if group: gid = self.getgroup_id(group) if not gid: error={"provider": domain, "message": "Group '%s' not available" % group, } return None, error url = url + "&group=%s" % (gid,) # itemsPerPage, startIndex, totalResults client = oauth.Client(self.consumer, self.oauth_token) resp, content = client.request(url, method) if int(resp.status) != 200: error={"provider": domain, "message": content, "status": int(resp.status) } return None, error feed = gdata.contacts.ContactsFeedFromString(content) for entry in feed.entry: #print entry.group_membership_info if entry.email: p = { 'displayName': entry.title.text, 'emails': [] } for email in entry.email: p['emails'].append({'value': email.address, 'primary': email.primary}) if not p['displayName']: p['displayName'] = email.address contacts.append(p) result = { 'entry': contacts, 'itemsPerPage': feed.items_per_page.text, 'startIndex': feed.start_index.text, 'totalResults': feed.total_results.text, } return result, None
def getcontacts(self, options, headers): start = int(options.get('start', 0)) page = int(options.get('page', 25)) group = options.get('group', None) contacts = [] userdomain = 'default' # google domains can have two contacts lists, the users and the domains # shared contacts. # shared contacts are only available in paid-for google domain accounts # and do not show the users full contacts list. I also did not find # docs on how to detect whether shared contacts is available or not, # so we will bypass this and simply use the users contacts list. #profile = self.account.get('profile', {}) #accounts = profile.get('accounts', [{}]) #if accounts[0].get('domain') == 'googleapps.com': # # set the domain so we get the shared contacts # userdomain = accounts[0].get('userid').split('@')[-1] url = ('http://www.google.com/m8/feeds/contacts/%s/full?' 'v=1&orderby=lastmodified&sortorder=descending' '&max-results=%d') % (userdomain, page) method = 'GET' if start > 0: url = url + "&start-index=%d" % (start, ) if group: gid = self.getgroup_id(group, headers) if not gid: error = { "provider": domain, "message": "Group '%s' not available" % group } return None, error url = url + "&group=%s" % (gid, ) # itemsPerPage, startIndex, totalResults requestor = OAuth2Requestor(self.consumer, self.oauth_token) resp, content = requestor.request(url, method, headers=headers) if int(resp.status) != 200: requestor.save_capture("contact fetch failure") error = { "provider": domain, "message": content, "status": int(resp.status) } return None, error feed = gdata.contacts.ContactsFeedFromString(content) for entry in feed.entry: #print entry.group_membership_info if entry.email: p = {'displayName': entry.title.text, 'emails': []} for email in entry.email: p['emails'].append({ 'value': email.address, 'primary': email.primary }) if not p['displayName']: p['displayName'] = email.address contacts.append(p) result = { 'entry': contacts, 'itemsPerPage': feed.items_per_page.text, 'startIndex': feed.start_index.text, 'totalResults': feed.total_results.text, } # create our pageData object if necessary next_start = int(feed.start_index.text) + int(feed.items_per_page.text) if next_start < int(feed.total_results.text): result['pageData'] = { 'start': next_start, 'page': page, 'group': group } return result, None