本文整理汇总了Golang中github.com/pomack/oauth2_client/go/oauth2_client.OAuth2Client类的典型用法代码示例。如果您正苦于以下问题:Golang OAuth2Client类的具体用法?Golang OAuth2Client怎么用?Golang OAuth2Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OAuth2Client类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:32,代码来源:service.go
示例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
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:58,代码来源:smugmug.go
示例3: HandleGenericOauthTestRequest
func HandleGenericOauthTestRequest(w http.ResponseWriter, req *http.Request, c oauth2_client.OAuth2Client, method, test_url_property, body string, useTemplate *template.Template) {
props := getProperties()
if req.Method == oauth2_client.POST {
if err := req.ParseForm(); err != nil {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(500)
io.WriteString(w, "Unable to parse form:\n\n")
io.WriteString(w, err.Error())
return
}
for k, arr := range req.Form {
for _, v := range arr {
props.Set(k, v)
}
}
}
for k, arr := range req.URL.Query() {
for _, v := range arr {
props.Set(k, v)
}
}
c.Initialize(props)
uri := props.GetAsString(test_url_property)
log.Printf("Client is: %T -> %#v", c, c)
var reader io.Reader = nil
if len(body) > 0 {
reader = bytes.NewBufferString(body)
}
resp, _, err := oauth2_client.AuthorizedRequest(c, method, nil, uri, nil, reader)
m := make(map[string]interface{})
isError := false
m["c"] = c
m["url"] = uri
if err != nil {
m["output"] = err.Error()
isError = true
} else {
b, err := httputil.DumpResponse(resp, true)
if err != nil {
m["output"] = err.Error()
isError = true
} else {
m["output"] = string(b)
}
}
if isError {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(500)
} else {
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(200)
}
err = useTemplate.Execute(w, m)
if err != nil {
oauth2_client.LogErrorf("Error: %T %v", err, err)
}
}
开发者ID:pomack,项目名称:oauth2_client.go,代码行数:57,代码来源:oauth2_client_tester.go
示例4: HandleGenericOauthRequest
func HandleGenericOauthRequest(c oauth2_client.OAuth2Client, w http.ResponseWriter, req *http.Request) {
uri := c.GenerateRequestTokenUrl(jsonhelper.NewJSONObject())
if len(uri) > 0 {
w.Header().Set("Location", uri)
w.WriteHeader(302)
} else {
w.WriteHeader(500)
}
}
开发者ID:pomack,项目名称:oauth2_client.go,代码行数:9,代码来源:oauth2_client_tester.go
示例5: 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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:56,代码来源:yahoo.go
示例6: 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
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:50,代码来源:service.go
示例7: 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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:49,代码来源:yahoo.go
示例8: 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
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:48,代码来源:service.go
示例9: 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
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:48,代码来源:service.go
示例10: 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
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:46,代码来源:service.go
示例11: 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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:43,代码来源:yahoo.go
示例12: 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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:41,代码来源:yahoo.go
示例13: 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
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:40,代码来源:google.go
示例14: 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
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:37,代码来源:google.go
示例15: 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
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:36,代码来源:facebook.go
示例16: HandleClientAccept
func HandleClientAccept(w http.ResponseWriter, req *http.Request) {
var c oauth2_client.OAuth2Client = nil
method := "GET"
headers := make(http.Header)
uri := ""
query := make(url.Values)
var reader io.Reader = nil
props := getProperties()
q := req.URL.Query()
oauth2_client.LogInfo("=================================")
oauth2_client.LogInfo("Received request from User: ")
reqBytes, _ := httputil.DumpRequest(req, true)
oauth2_client.LogInfo(string(reqBytes))
oauth2_client.LogInfo("=================================")
var useTemplate *template.Template = nil
var useTemplateData interface{} = nil
if site := q.Get("site"); len(site) > 0 {
if index := strings.Index(site, "?"); index >= 0 {
site = site[0:index]
}
m := make(map[string]interface{})
switch site {
case "facebook.com":
c = NewFacebookOauth2ClientTester(props)
uri = props.GetAsString("facebook.client.test_url")
useTemplate = PARSED_FACEBOOK_TEMPLATE
case "google.com":
c = NewGoogleOauth2ClientTester(props)
uri = props.GetAsString("google.client.test_url")
useTemplate = PARSED_GOOGLE_TEMPLATE
case "plus.google.com":
c = NewGooglePlusOauth2ClientTester(props)
uri = props.GetAsString("googleplus.client.test_url")
useTemplate = PARSED_GOOGLEPLUS_TEMPLATE
case "linkedin.com":
c = NewLinkedInOauth2ClientTester(props)
uri = props.GetAsString("linkedin.client.test_url")
useTemplate = PARSED_LINKEDIN_TEMPLATE
case "smugmug.com":
// smugmug doesn't support query strings properly
newRawUrl := strings.Replace(req.URL.String(), "site=smugmug.com?", "site=smugmug.com&", 1)
newUrl, _ := url.Parse(newRawUrl)
if newUrl != nil {
req.URL = newUrl
q = newUrl.Query()
}
c = NewSmugMugOauth2ClientTester(props)
uri = props.GetAsString("smugmug.client.test_url")
useTemplate = PARSED_SMUGMUG_TEMPLATE
case "twitter.com":
c = NewTwitterOauth2ClientTester(props)
uri = props.GetAsString("twitter.client.test_url")
useTemplate = PARSED_TWITTER_TEMPLATE
case "yahoo.com":
c = NewYahooOauth2ClientTester(props)
uri = props.GetAsString("yahoo.client.test_url")
useTemplate = PARSED_YAHOO_TEMPLATE
default:
log.Fatal("Unable to determine OAuth client to handle response: ", req.URL.String())
}
m["c"] = c
m["url"] = uri
m["output"] = ""
useTemplateData = m
} else {
log.Fatal("Unable to determine OAuth client to handle response: ", req.URL.String())
}
err := c.ExchangeRequestTokenForAccess(req)
if err != nil {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(500)
io.WriteString(w, "Error exchanging request token for access token\n\n")
io.WriteString(w, err.Error())
return
}
if useTemplate != nil {
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(200)
err = useTemplate.Execute(w, useTemplateData)
if err != nil {
oauth2_client.LogErrorf("Error: %T %v", err, err)
}
} else {
oauth2_client.LogInfo("Retrieving User Info...")
userInfo, err3 := c.RetrieveUserInfo()
oauth2_client.LogInfof("UserInfo: %T %v", userInfo, userInfo)
oauth2_client.LogInfof("Error: %T %v", err3, err3)
r, _, err2 := oauth2_client.AuthorizedRequest(c, method, headers, uri, query, reader)
if err2 != nil {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(500)
io.WriteString(w, "Error retrieving authorized response for "+uri+"?"+query.Encode()+"\n\n")
io.WriteString(w, err.Error())
return
}
h := w.Header()
for k, v := range r.Header {
for _, v1 := range v {
h.Add(k, v1)
//.........这里部分代码省略.........
开发者ID:pomack,项目名称:oauth2_client.go,代码行数:101,代码来源:oauth2_client_tester.go
示例17: 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(),
//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:101,代码来源:google.go
示例18: 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(),
//.........这里部分代码省略.........
开发者ID:pomack,项目名称:dsocial.go,代码行数:101,代码来源:google.go
注:本文中的github.com/pomack/oauth2_client/go/oauth2_client.OAuth2Client类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论