mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-12 03:05:14 +00:00
add a twitter service
This commit is contained in:
38
twitter/api/api.go
Normal file
38
twitter/api/api.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// Package api is a simple twitter api client
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
|
||||
"github.com/ChimeraCoder/anaconda"
|
||||
)
|
||||
|
||||
var (
|
||||
Token string
|
||||
TokenSecret string
|
||||
ConsumerKey string
|
||||
ConsumerSecret string
|
||||
|
||||
api *anaconda.TwitterApi
|
||||
)
|
||||
|
||||
func Init() {
|
||||
anaconda.SetConsumerKey(ConsumerKey)
|
||||
anaconda.SetConsumerSecret(ConsumerSecret)
|
||||
api = anaconda.NewTwitterApi(Token, TokenSecret)
|
||||
}
|
||||
|
||||
func Tweet(status string, args url.Values, rsp interface{}) error {
|
||||
tweet, err := api.PostTweet(status, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b, err := json.Marshal(tweet)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.Unmarshal(b, rsp)
|
||||
}
|
||||
Reference in New Issue
Block a user