forked from programmingthomas/instago
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusers.go
69 lines (62 loc) · 2.28 KB
/
users.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package instago
import "fmt"
//Gets basic information about a given user
//
//userID: a string representing the ID (not the username) of a given user
func (api InstagramAPI) UserDetail(userID string) (User, error) {
params := getEmptyMap()
result := api.DoRequest("users/"+userID, params)
data := result.Object("data")
return UserFromAPI(data), api.ErrorFromAPI(result)
}
//Query the users on Instagram and get a list of them back
//
//query: The description such as 'jack' or 'thomas' to search for
//
//max: (optional, default = 0) the number of users to return
func (api InstagramAPI) SearchUsers(query string, max int) ([]User, Pagination, error) {
params := getEmptyMap()
params["q"] = query
if max > 0 {
params["count"] = fmt.Sprintf("%d", max)
}
result := api.DoRequest("users/search", params)
data := result.ObjectArray("data")
users := make([]User, 0)
for _, user := range data {
users = append(users, UserFromAPI(user))
}
pagination := PaginationFromAPI(result.Object("pagination"))
err := api.ErrorFromAPI(result)
return users, pagination, err
}
//Will return an array of recently posted media objects by a user. Requires OAuth
//
//userId: string representing the user
//
//max: the greatest number of media objects to return
//
//before: (optional = "") posts before a certain ID
//
//after: (optional = "") posts after a certain ID
func (api InstagramAPI) RecentPostsByUser(userId string, max int, before, after string) ([]Media, Pagination, error) {
return api.GenericMediaListRequest("users/"+userId+"/media/recent", before, after, max)
}
//Gets the current user's feed (requires OAuth)
//
//before: (optional = "") posts before a certain ID
//
//after: (optional = "") posts after a certain ID
//
//max: (optional = 0) the greatest number of media objects to return
func (api InstagramAPI) Feed(before, after string, max int) ([]Media, Pagination, error) {
return api.GenericMediaListRequest("users/self/feed", before, after, max)
}
//Gets the posts like by the current user (requires OAuth)
//
//max: (optional = 0) the greatest number of posts to return
//
//before: (optional = 0) posts liked before a certain media ID
func (api InstagramAPI) Liked(max int, before string) ([]Media, Pagination, error) {
return api.GenericMediaListRequest("users/self/media/liked", before, "", max)
}