本文整理匯總了Golang中github.com/gokyle/keybase/api.Session.TwitterGetAuth方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.TwitterGetAuth方法的具體用法?Golang Session.TwitterGetAuth怎麽用?Golang Session.TwitterGetAuth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gokyle/keybase/api.Session
的用法示例。
在下文中一共展示了Session.TwitterGetAuth方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: authTwitter
func authTwitter(session *api.Session, keyRing *openpgp.KeyRing) {
username, err := readPrompt("Twitter username: ")
if err != nil {
fmt.Printf("Couldn't read from console: %v\n", err)
}
authData, err := session.TwitterGetAuth(username)
if err != nil {
fmt.Printf("Couldn't get authentication data: %v\n", err)
}
pub := session.User.PublicKeys["primary"]
if pub == nil {
fmt.Println("No public key for this account.")
os.Exit(1)
}
fmt.Printf("Fingerprint: %s\n", pub.Fingerprint)
signer := keyRing.Entity(pub.Fingerprint)
if signer == nil {
fmt.Println("No private key for this account.")
os.Exit(1)
}
ioutil.WriteFile("/tmp/authdata.json", authData, 0644)
sig, err := keyRing.Sign(authData, pub.Fingerprint)
if err != nil {
fmt.Printf("Couldn't sign authentication data: %v\n", err)
os.Exit(1)
}
proof, err := session.ServicePostAuth(sig, username, "twitter")
if err != nil {
fmt.Printf("Couldn't authenticate via Twitter: %v\n", err)
os.Exit(1)
}
fmt.Printf("Proof text: '%s'\n", proof.Text)
}