本文整理汇总了Golang中github.com/pomack/oauth2_client/go/oauth2_client.OAuth2Client.RetrieveUserInfo方法的典型用法代码示例。如果您正苦于以下问题:Golang OAuth2Client.RetrieveUserInfo方法的具体用法?Golang OAuth2Client.RetrieveUserInfo怎么用?Golang OAuth2Client.RetrieveUserInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pomack/oauth2_client/go/oauth2_client.OAuth2Client
的用法示例。
在下文中一共展示了OAuth2Client.RetrieveUserInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DeleteGroupOnExternalService
func DeleteGroupOnExternalService(client oauth2_client.OAuth2Client, cs ContactsService, ds DataStoreService, dsocialUserId, dsocialGroupId string) (bool, os.Error) {
if dsocialGroupId == "" || dsocialUserId == "" {
return false, nil
}
userInfo, err := client.RetrieveUserInfo()
if err != nil {
return true, err
}
externalServiceId := cs.ServiceId()
externalUserId := userInfo.Guid()
externalGroupId, err := ds.ExternalGroupIdForDsocialId(externalServiceId, externalUserId, dsocialUserId, dsocialGroupId)
if externalGroupId == "" || err != nil {
return externalGroupId == "", err
}
externalGroup, _, err := ds.RetrieveExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
if err != nil {
return true, err
}
if externalGroup == nil {
return false, err
}
_, err = cs.DeleteGroupOnExternalService(client, externalGroup)
if err != nil {
return true, err
}
_, err = ds.DeleteDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId)
if err != nil {
return true, err
}
_, err = ds.DeleteExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
return true, err
}
示例2: RetrieveContacts
func (p *SmugMugContactService) RetrieveContacts(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Contact, NextToken, os.Error) {
l := list.New()
var useErr os.Error
famResp, err := smugmug.RetrieveFamily(client, nil)
if err != nil {
useErr = err
}
if famResp != nil && famResp.Family != nil {
for _, u := range famResp.Family {
contact, err := p.handleRetrievedContact(client, ds, dsocialUserId, u.NickName, &u)
if contact != nil {
l.PushBack(contact)
}
if err != nil && useErr == nil {
useErr = err
}
}
}
if useErr != nil {
return p.listToContacts(l), nil, useErr
}
fansResp, err := smugmug.RetrieveFans(client, nil)
if err != nil {
useErr = err
}
if fansResp != nil && fansResp.Fans != nil {
for _, u := range fansResp.Fans {
contact, err := p.handleRetrievedContact(client, ds, dsocialUserId, u.NickName, &u)
if contact != nil {
l.PushBack(contact)
}
if err != nil && useErr == nil {
useErr = err
}
}
}
if useErr != nil {
return p.listToContacts(l), nil, useErr
}
userInfo, err := client.RetrieveUserInfo()
if err != nil {
return p.listToContacts(l), nil, err
}
userResp, err := smugmug.RetrieveUserInfo(client, userInfo.Username(), nil)
if err != nil {
useErr = err
}
if userResp != nil {
contact, err := p.handleRetrievedContact(client, ds, dsocialUserId, userResp.User.NickName, &userResp.User)
if contact != nil {
l.PushBack(contact)
}
if err != nil && useErr == nil {
useErr = err
}
}
return p.listToContacts(l), nil, useErr
}
示例3: RetrieveGroups
func (p *YahooContactService) RetrieveGroups(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Group, NextToken, error) {
var m url.Values
m = make(url.Values)
m.Add("count", "max")
if next == nil {
} else if start, ok := next.(int); ok {
m.Add("start", strconv.Itoa(start))
}
resp, err := yahoo.RetrieveCategories(client, m)
if resp == nil || resp.Categories.Categories == nil || len(resp.Categories.Categories) == 0 || err != nil {
return make([]*Group, 0), nil, err
}
groups := make([]*Group, len(resp.Categories.Categories))
externalServiceId := p.ServiceId()
userInfo, err := client.RetrieveUserInfo()
externalUserId := userInfo.Guid()
var useErr error = nil
for i, yahooGroup := range resp.Categories.Categories {
var externalGroupId string
if yahooGroup.Id > 0 {
externalGroupId = strconv.FormatInt(yahooGroup.Id, 10)
}
var origDsocialGroup *dm.Group = nil
dsocialGroupId := ""
if len(externalGroupId) > 0 {
dsocialGroupId, err = ds.DsocialIdForExternalGroupId(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
if err != nil {
if useErr == nil {
useErr = err
}
continue
}
if dsocialGroupId != "" {
origDsocialGroup, _, err = ds.RetrieveDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId)
if err != nil {
if useErr == nil {
useErr = err
}
continue
}
} else {
ds.StoreExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId, &yahooGroup)
}
}
var dsocialGroup *dm.Group = dm.YahooCategoryToDsocial(&yahooGroup, origDsocialGroup, dsocialUserId)
groups[i] = &Group{
ExternalServiceId: p.ServiceId(),
ExternalUserId: externalUserId,
ExternalGroupId: externalGroupId,
DsocialUserId: dsocialUserId,
DsocialGroupId: dsocialGroupId,
Value: dsocialGroup,
}
}
return groups, nil, useErr
}
示例4: CreateContactOnExternalService
func CreateContactOnExternalService(client oauth2_client.OAuth2Client, cs ContactsService, ds DataStoreService, dsocialUserId string, contact *dm.Contact) (*Contact, os.Error) {
if contact == nil {
return nil, nil
}
userInfo, err := client.RetrieveUserInfo()
if err != nil {
return nil, err
}
externalServiceId := cs.ServiceId()
externalUserId := userInfo.Guid()
externalContactId, err := ds.ExternalContactIdForDsocialId(externalServiceId, externalUserId, dsocialUserId, contact.Id)
if err != nil {
return nil, err
}
if externalContactId != "" {
originalContact, _, err := ds.RetrieveDsocialContact(dsocialUserId, contact.Id)
if err != nil {
return nil, err
}
return UpdateContactOnExternalService(client, cs, ds, dsocialUserId, originalContact, contact)
}
externalContact := cs.ConvertToExternalContact(contact, nil, dsocialUserId)
externalContact, externalContactId, err = cs.CreateContactOnExternalService(client, externalContact)
if err != nil {
return nil, err
}
externalContactId2, err := ds.StoreExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId, externalContact)
if err != nil {
return nil, err
}
fmt.Printf("[SERVICE]: extContactId: %s, extContactId2: %s\n", externalContactId, externalContactId2)
if externalContactId2 != "" {
externalContactId = externalContactId2
}
dsocialContactForExternal := cs.ConvertToDsocialContact(externalContact, contact, dsocialUserId)
dsocialContactForExternal, err = ds.StoreDsocialContactForExternalContact(externalServiceId, externalUserId, externalContactId, dsocialUserId, dsocialContactForExternal)
if err != nil {
return nil, err
}
_, _, err = ds.StoreDsocialExternalContactMapping(externalServiceId, externalUserId, externalContactId, dsocialUserId, dsocialContactForExternal.Id)
outContact := &Contact{
ExternalServiceId: externalServiceId,
ExternalUserId: externalUserId,
ExternalContactId: externalContactId,
DsocialUserId: dsocialUserId,
DsocialContactId: dsocialContactForExternal.Id,
Value: dsocialContactForExternal,
}
return outContact, err
}
示例5: RetrieveContacts
func (p *YahooContactService) RetrieveContacts(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Contact, NextToken, error) {
var m url.Values
m = make(url.Values)
m.Add("count", "max")
if next == nil {
} else if start, ok := next.(int); ok {
m.Add("start", strconv.Itoa(start))
}
resp, err := yahoo.RetrieveContacts(client, m)
if resp == nil || resp.Contacts.Contacts == nil || len(resp.Contacts.Contacts) == 0 || err != nil {
return make([]*Contact, 0), nil, err
}
contacts := make([]*Contact, len(resp.Contacts.Contacts))
externalServiceId := p.ServiceId()
userInfo, err := client.RetrieveUserInfo()
externalUserId := userInfo.Guid()
var useErr error = nil
for i, yahooContact := range resp.Contacts.Contacts {
externalContactId := strconv.FormatInt(yahooContact.Id, 10)
dsocialContactId := ""
var origDsocialContact *dm.Contact = nil
if len(externalContactId) > 0 {
dsocialContactId, err = ds.DsocialIdForExternalContactId(externalServiceId, externalUserId, dsocialUserId, externalContactId)
if err != nil {
useErr = err
continue
}
if dsocialContactId != "" {
origDsocialContact, _, err = ds.RetrieveDsocialContactForExternalContact(externalServiceId, externalUserId, externalContactId, dsocialUserId)
if err != nil {
useErr = err
continue
}
} else {
ds.StoreExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId, &yahooContact)
}
}
dsocialContact := dm.YahooContactToDsocial(&yahooContact, origDsocialContact, dsocialUserId)
contacts[i] = &Contact{
ExternalServiceId: p.ServiceId(),
ExternalUserId: externalUserId,
ExternalContactId: externalContactId,
DsocialUserId: dsocialUserId,
DsocialContactId: dsocialContactId,
Value: dsocialContact,
}
}
return contacts, nil, useErr
}
示例6: UpdateGroupOnExternalService
func UpdateGroupOnExternalService(client oauth2_client.OAuth2Client, cs ContactsService, ds DataStoreService, dsocialUserId string, originalGroup, group *dm.Group) (*Group, os.Error) {
if group == nil || originalGroup == nil {
return nil, nil
}
userInfo, err := client.RetrieveUserInfo()
if err != nil {
return nil, err
}
externalServiceId := cs.ServiceId()
externalUserId := userInfo.Guid()
externalGroupId, err := ds.ExternalGroupIdForDsocialId(externalServiceId, externalUserId, dsocialUserId, originalGroup.Id)
if err != nil {
return nil, err
}
if externalGroupId == "" {
return CreateGroupOnExternalService(client, cs, ds, dsocialUserId, group)
}
originalExternalGroup, _, err := ds.RetrieveExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
if err != nil {
return nil, err
}
latestExternalGroup := cs.ConvertToExternalGroup(group, originalExternalGroup, dsocialUserId)
latestExternalGroup2, externalGroupId2, err := cs.UpdateGroupOnExternalService(client, originalExternalGroup, latestExternalGroup)
if err != nil {
return nil, err
}
if latestExternalGroup2 != nil {
latestExternalGroup = latestExternalGroup2
}
if externalGroupId2 != "" {
externalGroupId = externalGroupId2
}
latestDsocialGroupForExternal := cs.ConvertToDsocialGroup(latestExternalGroup, originalGroup, dsocialUserId)
_, err = ds.StoreExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId, latestExternalGroup)
if err != nil {
return nil, err
}
latestDsocialGroupForExternal, err = ds.StoreDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId, latestDsocialGroupForExternal)
outGroup := &Group{
ExternalServiceId: externalServiceId,
ExternalUserId: externalUserId,
ExternalGroupId: externalGroupId,
DsocialUserId: dsocialUserId,
DsocialGroupId: latestDsocialGroupForExternal.Id,
Value: latestDsocialGroupForExternal,
}
return outGroup, err
}
示例7: UpdateContactOnExternalService
func UpdateContactOnExternalService(client oauth2_client.OAuth2Client, cs ContactsService, ds DataStoreService, dsocialUserId string, originalContact, contact *dm.Contact) (*Contact, os.Error) {
if contact == nil || originalContact == nil {
return nil, nil
}
userInfo, err := client.RetrieveUserInfo()
if err != nil {
return nil, err
}
externalServiceId := cs.ServiceId()
externalUserId := userInfo.Guid()
externalContactId, err := ds.ExternalContactIdForDsocialId(externalServiceId, externalUserId, dsocialUserId, originalContact.Id)
if err != nil {
return nil, err
}
if externalContactId == "" {
return CreateContactOnExternalService(client, cs, ds, dsocialUserId, contact)
}
originalExternalContact, _, err := ds.RetrieveExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId)
if err != nil {
return nil, err
}
latestExternalContact := cs.ConvertToExternalContact(contact, originalExternalContact, dsocialUserId)
latestExternalContact2, externalContactId2, err := cs.UpdateContactOnExternalService(client, originalExternalContact, latestExternalContact)
if err != nil {
return nil, err
}
if latestExternalContact2 != nil {
latestExternalContact = latestExternalContact2
}
if externalContactId2 != "" {
externalContactId = externalContactId2
}
latestDsocialContactForExternal := cs.ConvertToDsocialContact(latestExternalContact, originalContact, dsocialUserId)
_, err = ds.StoreExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId, latestExternalContact)
if err != nil {
return nil, err
}
latestDsocialContactForExternal, err = ds.StoreDsocialContactForExternalContact(externalServiceId, externalUserId, externalContactId, dsocialUserId, latestDsocialContactForExternal)
outContact := &Contact{
ExternalServiceId: externalServiceId,
ExternalUserId: externalUserId,
ExternalContactId: externalContactId,
DsocialUserId: dsocialUserId,
DsocialContactId: latestDsocialContactForExternal.Id,
Value: latestDsocialContactForExternal,
}
return outContact, err
}
示例8: CreateGroupOnExternalService
func CreateGroupOnExternalService(client oauth2_client.OAuth2Client, cs ContactsService, ds DataStoreService, dsocialUserId string, group *dm.Group) (*Group, os.Error) {
if group == nil {
return nil, nil
}
userInfo, err := client.RetrieveUserInfo()
if err != nil {
return nil, err
}
externalServiceId := cs.ServiceId()
externalUserId := userInfo.Guid()
externalGroupId, err := ds.ExternalGroupIdForDsocialId(externalServiceId, externalUserId, dsocialUserId, group.Id)
if err != nil {
return nil, err
}
if externalGroupId != "" {
originalGroup, _, err := ds.RetrieveDsocialGroup(dsocialUserId, group.Id)
if err != nil {
return nil, err
}
return UpdateGroupOnExternalService(client, cs, ds, dsocialUserId, originalGroup, group)
}
externalGroup := cs.ConvertToExternalGroup(group, nil, dsocialUserId)
externalGroup, externalGroupId, err = cs.CreateGroupOnExternalService(client, externalGroup)
if err != nil {
return nil, err
}
externalGroupId, err = ds.StoreExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId, externalGroup)
if err != nil {
return nil, err
}
dsocialGroupForExternal := cs.ConvertToDsocialGroup(externalGroup, group, dsocialUserId)
dsocialGroupForExternal, err = ds.StoreDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId, dsocialGroupForExternal)
if err != nil {
return nil, err
}
_, _, err = ds.StoreDsocialExternalGroupMapping(externalServiceId, externalUserId, externalGroupId, dsocialUserId, dsocialGroupForExternal.Id)
outGroup := &Group{
ExternalServiceId: externalServiceId,
ExternalUserId: externalUserId,
ExternalGroupId: externalGroupId,
DsocialUserId: dsocialUserId,
DsocialGroupId: dsocialGroupForExternal.Id,
Value: dsocialGroupForExternal,
}
return outGroup, err
}
示例9: RetrieveGroup
func (p *YahooContactService) RetrieveGroup(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, groupId string) (*Group, error) {
resp, err := yahoo.RetrieveCategory(client, groupId, nil)
if resp == nil || err != nil {
return nil, err
}
yahooGroup := &resp.Category
externalServiceId := p.ServiceId()
userInfo, err := client.RetrieveUserInfo()
externalUserId := userInfo.Guid()
useErr := err
var externalGroupId string
if yahooGroup.Id > 0 {
externalGroupId = strconv.FormatInt(yahooGroup.Id, 10)
}
dsocialGroupId := ""
var origDsocialGroup *dm.Group = nil
if len(externalGroupId) > 0 {
dsocialGroupId, err = ds.DsocialIdForExternalGroupId(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
if err != nil {
if useErr == nil {
useErr = err
}
}
if dsocialGroupId != "" {
origDsocialGroup, _, err = ds.RetrieveDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId)
if err != nil && useErr == nil {
useErr = err
}
} else {
ds.StoreExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId, yahooGroup)
}
}
var dsocialGroup *dm.Group = dm.YahooCategoryToDsocial(yahooGroup, origDsocialGroup, dsocialUserId)
group := &Group{
ExternalServiceId: p.ServiceId(),
ExternalUserId: externalUserId,
ExternalGroupId: externalGroupId,
DsocialUserId: dsocialUserId,
DsocialGroupId: dsocialGroupId,
Value: dsocialGroup,
}
return group, useErr
}
示例10: RetrieveContact
func (p *YahooContactService) RetrieveContact(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, contactId string) (*Contact, error) {
resp, err := yahoo.RetrieveContact(client, contactId, nil)
if resp == nil || err != nil {
return nil, err
}
yahooContact := &resp.Contact
externalServiceId := p.ServiceId()
userInfo, err := client.RetrieveUserInfo()
externalUserId := userInfo.Guid()
useErr := err
dsocialContactId := ""
var origDsocialContact *dm.Contact = nil
var externalContactId string
if yahooContact.Id > 0 {
externalContactId = strconv.FormatInt(yahooContact.Id, 10)
}
if len(externalContactId) > 0 {
dsocialContactId, err = ds.DsocialIdForExternalContactId(externalServiceId, externalUserId, dsocialUserId, contactId)
if err != nil {
useErr = err
}
if dsocialContactId != "" {
origDsocialContact, _, err = ds.RetrieveDsocialContactForExternalContact(externalServiceId, externalUserId, externalContactId, dsocialUserId)
if err != nil && useErr == nil {
useErr = err
}
} else {
ds.StoreExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId, yahooContact)
}
}
dsocialContact := dm.YahooContactToDsocial(yahooContact, origDsocialContact, dsocialUserId)
contact := &Contact{
ExternalServiceId: p.ServiceId(),
ExternalUserId: externalUserId,
ExternalContactId: externalContactId,
DsocialUserId: dsocialUserId,
DsocialContactId: dsocialContactId,
Value: dsocialContact,
}
return contact, useErr
}
示例11: RetrieveGroup
func (p *GoogleContactService) RetrieveGroup(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, groupId string) (*Group, os.Error) {
resp, err := google.RetrieveGroup(client, groupId, nil)
if resp == nil || resp.Entry == nil || err != nil {
return nil, err
}
googleGroup := resp.Entry
externalServiceId := p.ServiceId()
userInfo, err := client.RetrieveUserInfo()
externalUserId := userInfo.Guid()
useErr := err
externalGroupId := googleGroup.GroupId()
dsocialGroupId := ""
var origDsocialGroup *dm.Group = nil
if len(externalGroupId) > 0 {
dsocialGroupId, err = ds.DsocialIdForExternalGroupId(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
if err != nil {
if useErr == nil {
useErr = err
}
}
if dsocialGroupId != "" {
origDsocialGroup, _, err = ds.RetrieveDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId)
if err != nil && useErr == nil {
useErr = err
}
} else {
ds.StoreExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId, googleGroup)
}
}
var dsocialGroup *dm.Group = dm.GoogleGroupToDsocial(googleGroup, origDsocialGroup, dsocialUserId)
group := &Group{
ExternalServiceId: p.ServiceId(),
ExternalUserId: externalUserId,
ExternalGroupId: externalGroupId,
DsocialUserId: dsocialUserId,
DsocialGroupId: dsocialGroupId,
Value: dsocialGroup,
}
return group, useErr
}
示例12: RetrieveContact
func (p *GoogleContactService) RetrieveContact(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, contactId string) (*Contact, os.Error) {
googleContact, err := google.RetrieveContact(client, contactId, nil)
if googleContact == nil || err != nil {
return nil, err
}
externalServiceId := p.ServiceId()
userInfo, err := client.RetrieveUserInfo()
externalUserId := userInfo.Guid()
useErr := err
dsocialContactId := ""
var origDsocialContact *dm.Contact = nil
externalContactId := googleContact.ContactId()
if len(externalContactId) > 0 {
dsocialContactId, err = ds.DsocialIdForExternalContactId(externalServiceId, externalUserId, dsocialUserId, contactId)
if err != nil {
useErr = err
}
if dsocialContactId != "" {
origDsocialContact, _, err = ds.RetrieveDsocialContactForExternalContact(externalServiceId, externalUserId, externalContactId, dsocialUserId)
if err != nil && useErr == nil {
useErr = err
}
} else {
ds.StoreExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId, googleContact)
}
}
dsocialContact := dm.GoogleContactToDsocial(googleContact, origDsocialContact, dsocialUserId)
contact := &Contact{
ExternalServiceId: p.ServiceId(),
ExternalUserId: googleContact.ContactUserId(),
ExternalContactId: googleContact.ContactId(),
DsocialUserId: dsocialUserId,
DsocialContactId: dsocialContactId,
Value: dsocialContact,
}
return contact, useErr
}
示例13: handleRetrievedContact
func (p *FacebookContactService) handleRetrievedContact(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, contactId string, extContact *facebook.Contact) (contact *Contact, err os.Error) {
if extContact == nil {
return nil, nil
}
externalServiceId := p.ServiceId()
userInfo, err := client.RetrieveUserInfo()
externalUserId := userInfo.Guid()
var useErr os.Error = nil
dsocialContactId := ""
var origDsocialContact *dm.Contact = nil
externalContactId := extContact.Id
if len(externalContactId) > 0 {
dsocialContactId, err = ds.DsocialIdForExternalContactId(externalServiceId, externalUserId, dsocialUserId, contactId)
if err != nil {
useErr = err
}
if dsocialContactId != "" {
origDsocialContact, _, err = ds.RetrieveDsocialContactForExternalContact(externalServiceId, externalUserId, externalContactId, dsocialUserId)
if err != nil && useErr == nil {
useErr = err
}
} else {
ds.StoreExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId, extContact)
}
}
dsocialContact := dm.FacebookContactToDsocial(extContact, origDsocialContact, dsocialUserId)
contact = &Contact{
ExternalServiceId: p.ServiceId(),
ExternalUserId: externalUserId,
ExternalContactId: externalContactId,
DsocialUserId: dsocialUserId,
DsocialContactId: dsocialContactId,
Value: dsocialContact,
}
return contact, useErr
}
示例14: RetrieveGroups
func (p *GoogleContactService) RetrieveGroups(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Group, NextToken, os.Error) {
var m url.Values
if next == nil {
} else if s, ok := next.(string); ok {
if s != "" {
if strings.HasPrefix(s, "https://www.google.com/") {
uri, err := url.Parse(s)
if err == nil {
q, err := url.ParseQuery(uri.RawQuery)
if err == nil {
m = q
}
}
}
if m == nil {
m = make(url.Values)
m.Add("q", s)
}
}
} else if maxResults, ok := next.(int); ok {
m = make(url.Values)
m.Add("max-results", strconv.Itoa(maxResults))
} else if maxResults, ok := next.(int64); ok {
m = make(url.Values)
m.Add("max-results", strconv.Itoa64(maxResults))
} else if gq, ok := next.(*google.GroupQuery); ok {
m = make(url.Values)
if gq.Alt != "" {
m.Add("alt", gq.Alt)
}
if gq.Q != "" {
m.Add("q", gq.Q)
}
if gq.MaxResults > 0 {
m.Add("max-results", strconv.Itoa64(gq.MaxResults))
}
if gq.StartIndex > 0 {
m.Add("start-index", strconv.Itoa64(gq.StartIndex))
}
if gq.UpdatedMin != "" {
m.Add("updated-min", gq.UpdatedMin)
}
if gq.OrderBy != "" {
m.Add("orderby", gq.OrderBy)
}
if gq.ShowDeleted {
m.Add("showdeleted", "true")
}
if gq.RequireAllDeleted {
m.Add("requirealldeleted", "true")
}
if gq.SortOrder != "" {
m.Add("sortorder", gq.SortOrder)
}
}
resp, err := google.RetrieveGroups(client, m)
var theNextToken NextToken = nil
if resp != nil && resp.Feed != nil && resp.Feed.Links != nil && len(resp.Feed.Links) > 0 {
for _, link := range resp.Feed.Links {
if link.Rel == "next" {
theNextToken = link.Href
}
}
}
if resp == nil || resp.Feed == nil || resp.Feed.Entries == nil || len(resp.Feed.Entries) == 0 || err != nil {
return make([]*Group, 0), theNextToken, err
}
groups := make([]*Group, len(resp.Feed.Entries))
externalServiceId := p.ServiceId()
userInfo, err := client.RetrieveUserInfo()
externalUserId := userInfo.Guid()
var useErr os.Error = nil
for i, googleGroup := range resp.Feed.Entries {
externalGroupId := googleGroup.GroupId()
var origDsocialGroup *dm.Group = nil
dsocialGroupId := ""
if len(externalGroupId) > 0 {
dsocialGroupId, err = ds.DsocialIdForExternalGroupId(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
if err != nil {
if useErr == nil {
useErr = err
}
continue
}
if dsocialGroupId != "" {
origDsocialGroup, _, err = ds.RetrieveDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId)
if err != nil {
if useErr == nil {
useErr = err
}
continue
}
} else {
ds.StoreExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId, &googleGroup)
}
}
var dsocialGroup *dm.Group = dm.GoogleGroupToDsocial(&googleGroup, origDsocialGroup, dsocialUserId)
groups[i] = &Group{
ExternalServiceId: p.ServiceId(),
ExternalUserId: googleGroup.GroupUserId(),
//.........这里部分代码省略.........
示例15: RetrieveContacts
func (p *GoogleContactService) RetrieveContacts(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Contact, NextToken, error) {
var m url.Values
if next == nil {
} else if s, ok := next.(string); ok {
if s != "" {
if strings.HasPrefix(s, "https://www.google.com/") || strings.HasPrefix(s, "http://www.google.com/") {
uri, err := url.Parse(s)
if err == nil {
q, err := url.ParseQuery(uri.RawQuery)
if err == nil {
m = q
}
}
}
if m == nil {
m = make(url.Values)
m.Add("q", s)
}
}
} else if maxResults, ok := next.(int); ok {
m = make(url.Values)
m.Add("max-results", strconv.Itoa(maxResults))
} else if maxResults, ok := next.(int64); ok {
m = make(url.Values)
m.Add("max-results", strconv.FormatInt(maxResults, 10))
} else if cq, ok := next.(*google.ContactQuery); ok {
m = make(url.Values)
if cq.Alt != "" {
m.Add("alt", cq.Alt)
}
if cq.Q != "" {
m.Add("q", cq.Q)
}
if cq.MaxResults > 0 {
m.Add("max-results", strconv.FormatInt(cq.MaxResults, 10))
}
if cq.StartIndex > 0 {
m.Add("start-index", strconv.FormatInt(cq.StartIndex, 10))
}
if cq.UpdatedMin != "" {
m.Add("updated-min", cq.UpdatedMin)
}
if cq.OrderBy != "" {
m.Add("orderby", cq.OrderBy)
}
if cq.ShowDeleted {
m.Add("showdeleted", "true")
}
if cq.RequireAllDeleted {
m.Add("requirealldeleted", "true")
}
if cq.SortOrder != "" {
m.Add("sortorder", cq.SortOrder)
}
if cq.Group != "" {
m.Add("group", cq.Group)
}
}
feed, err := google.RetrieveContacts(client, m)
var theNextToken NextToken = nil
if feed != nil && feed.Links != nil && len(feed.Links) > 0 {
for _, link := range feed.Links {
if link.Rel == "next" {
theNextToken = link.Href
break
}
}
}
if feed == nil || feed.Entries == nil || len(feed.Entries) == 0 || err != nil {
return make([]*Contact, 0), theNextToken, err
}
contacts := make([]*Contact, len(feed.Entries))
externalServiceId := p.ServiceId()
userInfo, err := client.RetrieveUserInfo()
externalUserId := userInfo.Guid()
var useErr error = nil
for i, googleContact := range feed.Entries {
externalContactId := googleContact.ContactId()
dsocialContactId := ""
var origDsocialContact *dm.Contact = nil
if len(externalContactId) > 0 {
dsocialContactId, err = ds.DsocialIdForExternalContactId(externalServiceId, externalUserId, dsocialUserId, externalContactId)
if err != nil {
useErr = err
continue
}
if dsocialContactId != "" {
origDsocialContact, _, err = ds.RetrieveDsocialContactForExternalContact(externalServiceId, externalUserId, externalContactId, dsocialUserId)
if err != nil {
useErr = err
continue
}
} else {
ds.StoreExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId, &googleContact)
}
}
dsocialContact := dm.GoogleContactToDsocial(&googleContact, origDsocialContact, dsocialUserId)
contacts[i] = &Contact{
ExternalServiceId: p.ServiceId(),
ExternalUserId: googleContact.ContactUserId(),
//.........这里部分代码省略.........