forked from programmingthomas/instago
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmedia.go
More file actions
45 lines (40 loc) · 1.43 KB
/
media.go
File metadata and controls
45 lines (40 loc) · 1.43 KB
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
package instago
import "fmt"
//Gets details for media with the given ID
//
//mediaId: A string representing the ID of the media to get info on
func (api InstagramAPI) Media(mediaId string) Media {
params := getEmptyMap()
response := api.DoRequest("media/"+mediaId, params)
return MediaFromAPI(response.Object("data"))
}
//Gets a list of popular media at the moment
func (api InstagramAPI) Popular() ([]Media, Pagination, error) {
return api.GenericMediaListRequest("media/popular", "", "", 0)
}
//Gets a list of media posted from a certain location recently.
//N.B. This seems a bit unreliable...
//
//lat: The latitude to search near
//
//long: The longitude to search near
//
//distance: (optional = 0) The number of meters to search within
func (api InstagramAPI) LocationSearch(lat, lng, distance float64) ([]Media, Pagination, error) {
//Unfortunately I couldn't use GenericMediaListRequest because it takes in location
params := getEmptyMap()
if distance > 0 {
params["distance"] = fmt.Sprintf("%f", distance)
}
params["lat"] = fmt.Sprintf("%f", lat)
params["lng"] = fmt.Sprintf("%f", lng)
results := api.DoRequest("media/search", params)
data := results.ObjectArray("data")
media_objects := make([]Media, 0)
for _, media := range data {
media_objects = append(media_objects, MediaFromAPI(media))
}
pagination := PaginationFromAPI(results.Object("pagination"))
err := api.ErrorFromAPI(results)
return media_objects, pagination, err
}