Fix Instagram API
Instagram API working again, in question is for how long...
This commit is contained in:
parent
ee82fdf57e
commit
d1b91fcee3
150
instagram/api.go
150
instagram/api.go
|
@ -17,56 +17,144 @@ import (
|
|||
|
||||
type InstagramListResponse struct {
|
||||
Tag struct {
|
||||
Name string `json:"name"`
|
||||
ContentAdvisory interface{} `json:"content_advisory"`
|
||||
Media struct {
|
||||
Nodes []struct {
|
||||
CommentsDisabled bool `json:"comments_disabled"`
|
||||
ID string `json:"id"`
|
||||
Caption string `json:"caption"`
|
||||
DisplaySrc string `json:"display_src"`
|
||||
IsVideo bool `json:"is_video"`
|
||||
Dimensions struct {
|
||||
Height int `json:"height"`
|
||||
Width int `json:"width"`
|
||||
} `json:"dimensions"`
|
||||
Owner struct {
|
||||
ID string `json:"id"`
|
||||
} `json:"owner"`
|
||||
ThumbnailSrc string `json:"thumbnail_src"`
|
||||
IsVideo bool `json:"is_video"`
|
||||
Code string `json:"code"`
|
||||
Date int `json:"date"`
|
||||
} `json:"nodes"`
|
||||
PageInfo struct {
|
||||
EndCursor string `json:"end_cursor"`
|
||||
HasNextPage bool `json:"has_next_page"`
|
||||
StartCursor string `json:"start_cursor"`
|
||||
HasPreviousPage bool `json:"has_previous_page"`
|
||||
} `json:"page_info"`
|
||||
DisplaySrc string `json:"display_src"`
|
||||
Caption string `json:"caption"`
|
||||
Comments struct {
|
||||
Count int `json:"count"`
|
||||
} `json:"comments"`
|
||||
Likes struct {
|
||||
Count int `json:"count"`
|
||||
} `json:"likes"`
|
||||
} `json:"nodes"`
|
||||
Count int `json:"count"`
|
||||
PageInfo struct {
|
||||
HasNextPage bool `json:"has_next_page"`
|
||||
EndCursor string `json:"end_cursor"`
|
||||
} `json:"page_info"`
|
||||
} `json:"media"`
|
||||
TopPosts struct {
|
||||
Nodes []struct {
|
||||
ID string `json:"id"`
|
||||
Dimensions struct {
|
||||
Height int `json:"height"`
|
||||
Width int `json:"width"`
|
||||
} `json:"dimensions"`
|
||||
Owner struct {
|
||||
ID string `json:"id"`
|
||||
} `json:"owner"`
|
||||
ThumbnailSrc string `json:"thumbnail_src"`
|
||||
IsVideo bool `json:"is_video"`
|
||||
Code string `json:"code"`
|
||||
Date int `json:"date"`
|
||||
DisplaySrc string `json:"display_src"`
|
||||
Caption string `json:"caption"`
|
||||
Comments struct {
|
||||
Count int `json:"count"`
|
||||
} `json:"comments"`
|
||||
Likes struct {
|
||||
Count int `json:"count"`
|
||||
} `json:"likes"`
|
||||
} `json:"nodes"`
|
||||
} `json:"top_posts"`
|
||||
} `json:"tag"`
|
||||
}
|
||||
|
||||
type InstagramPostResponse struct {
|
||||
Media struct {
|
||||
Owner struct {
|
||||
ProfilePicURL string `json:"profile_pic_url"`
|
||||
HasBlockedViewer bool `json:"has_blocked_viewer"`
|
||||
Username string `json:"username"`
|
||||
FullName string `json:"full_name"`
|
||||
RequestedByViewer bool `json:"requested_by_viewer"`
|
||||
FollowedByViewer bool `json:"followed_by_viewer"`
|
||||
IsPrivate bool `json:"is_private"`
|
||||
Graphql struct {
|
||||
ShortcodeMedia struct {
|
||||
Typename string `json:"__typename"`
|
||||
ID string `json:"id"`
|
||||
BlockedByViewer bool `json:"blocked_by_viewer"`
|
||||
IsUnpublished bool `json:"is_unpublished"`
|
||||
} `json:"owner"`
|
||||
CaptionIsEdited bool `json:"caption_is_edited"`
|
||||
Shortcode string `json:"shortcode"`
|
||||
Dimensions struct {
|
||||
Height int `json:"height"`
|
||||
Width int `json:"width"`
|
||||
} `json:"dimensions"`
|
||||
DisplayURL string `json:"display_url"`
|
||||
VideoURL string `json:"video_url"`
|
||||
DisplaySrc string `json:"display_src"`
|
||||
CommentsDisabled bool `json:"comments_disabled"`
|
||||
Code string `json:"code"`
|
||||
IsAd bool `json:"is_ad"`
|
||||
VideoViewCount int `json:"video_view_count"`
|
||||
IsVideo bool `json:"is_video"`
|
||||
Caption string `json:"caption"`
|
||||
EdgeMediaToTaggedUser struct {
|
||||
Edges []interface{} `json:"edges"`
|
||||
} `json:"edge_media_to_tagged_user"`
|
||||
EdgeMediaToCaption struct {
|
||||
Edges []struct {
|
||||
Node struct {
|
||||
Text string `json:"text"`
|
||||
} `json:"node"`
|
||||
} `json:"edges"`
|
||||
} `json:"edge_media_to_caption"`
|
||||
CaptionIsEdited bool `json:"caption_is_edited"`
|
||||
EdgeMediaToComment struct {
|
||||
Count int `json:"count"`
|
||||
PageInfo struct {
|
||||
HasNextPage bool `json:"has_next_page"`
|
||||
EndCursor string `json:"end_cursor"`
|
||||
} `json:"page_info"`
|
||||
Edges []struct {
|
||||
Node struct {
|
||||
ID string `json:"id"`
|
||||
Date int `json:"date"`
|
||||
VideoViews int `json:"video_views"`
|
||||
} `json:"media"`
|
||||
Text string `json:"text"`
|
||||
CreatedAt int `json:"created_at"`
|
||||
Owner struct {
|
||||
ID string `json:"id"`
|
||||
ProfilePicURL string `json:"profile_pic_url"`
|
||||
Username string `json:"username"`
|
||||
} `json:"owner"`
|
||||
} `json:"node"`
|
||||
} `json:"edges"`
|
||||
} `json:"edge_media_to_comment"`
|
||||
CommentsDisabled bool `json:"comments_disabled"`
|
||||
TakenAtTimestamp int `json:"taken_at_timestamp"`
|
||||
EdgeMediaPreviewLike struct {
|
||||
Count int `json:"count"`
|
||||
Edges []struct {
|
||||
Node struct {
|
||||
ID string `json:"id"`
|
||||
ProfilePicURL string `json:"profile_pic_url"`
|
||||
Username string `json:"username"`
|
||||
} `json:"node"`
|
||||
} `json:"edges"`
|
||||
} `json:"edge_media_preview_like"`
|
||||
EdgeMediaToSponsorUser struct {
|
||||
Edges []interface{} `json:"edges"`
|
||||
} `json:"edge_media_to_sponsor_user"`
|
||||
Location interface{} `json:"location"`
|
||||
ViewerHasLiked bool `json:"viewer_has_liked"`
|
||||
Owner struct {
|
||||
ID string `json:"id"`
|
||||
ProfilePicURL string `json:"profile_pic_url"`
|
||||
Username string `json:"username"`
|
||||
FollowedByViewer bool `json:"followed_by_viewer"`
|
||||
FullName string `json:"full_name"`
|
||||
IsPrivate bool `json:"is_private"`
|
||||
RequestedByViewer bool `json:"requested_by_viewer"`
|
||||
IsUnpublished bool `json:"is_unpublished"`
|
||||
BlockedByViewer bool `json:"blocked_by_viewer"`
|
||||
HasBlockedViewer bool `json:"has_blocked_viewer"`
|
||||
} `json:"owner"`
|
||||
IsAd bool `json:"is_ad"`
|
||||
EdgeWebMediaToRelatedMedia struct {
|
||||
Edges []interface{} `json:"edges"`
|
||||
} `json:"edge_web_media_to_related_media"`
|
||||
} `json:"shortcode_media"`
|
||||
} `json:"graphql"`
|
||||
}
|
||||
|
||||
func LoadList(token string) (*InstagramListResponse, error) {
|
||||
|
|
|
@ -46,32 +46,32 @@ func iterList(list *InstagramListResponse) string {
|
|||
log.Printf("Can't load Instagram post %s: %+v", image.Code, err)
|
||||
continue
|
||||
}
|
||||
if post.Media.IsAd {
|
||||
if post.Graphql.ShortcodeMedia.IsAd {
|
||||
continue
|
||||
}
|
||||
var US database.User
|
||||
if database.Db.Model(database.User{}).Where("name = ? AND service = ?", post.Media.Owner.Username, database.Instagram).First(&US).Count(&count); count == 0 {
|
||||
US.DisplayName = post.Media.Owner.FullName
|
||||
US.Name = post.Media.Owner.Username
|
||||
if database.Db.Model(database.User{}).Where("name = ? AND service = ?", post.Graphql.ShortcodeMedia.Owner.Username, database.Instagram).First(&US).Count(&count); count == 0 {
|
||||
US.DisplayName = post.Graphql.ShortcodeMedia.Owner.FullName
|
||||
US.Name = post.Graphql.ShortcodeMedia.Owner.Username
|
||||
US.Service = database.Instagram
|
||||
US.Blocked = false
|
||||
database.Db.Create(&US)
|
||||
}
|
||||
if post.Media.IsVideo {
|
||||
log.Printf("Found video %s from %s", post.Media.Code, post.Media.Owner.Username)
|
||||
name, uname := ImageNameGenerator(post.Media.Code)
|
||||
res, err := GetHTTPResource(post.Media.VideoURL)
|
||||
if post.Graphql.ShortcodeMedia.IsVideo {
|
||||
log.Printf("Found video %s from %s", post.Graphql.ShortcodeMedia.Shortcode, post.Graphql.ShortcodeMedia.Owner.Username)
|
||||
name, uname := ImageNameGenerator(post.Graphql.ShortcodeMedia.Shortcode)
|
||||
res, err := GetHTTPResource(post.Graphql.ShortcodeMedia.VideoURL)
|
||||
if err != nil {
|
||||
log.Printf("Can't load video %s: %+v", post.Media.Code, err)
|
||||
log.Printf("Can't load video %s: %+v", post.Graphql.ShortcodeMedia.Shortcode, err)
|
||||
continue
|
||||
}
|
||||
defer res.Body.Close()
|
||||
ext, err := DownloadMedia(res.Body, name, true)
|
||||
if err != nil {
|
||||
log.Printf("Can't load video %s: %+v", post.Media.Code, err)
|
||||
log.Printf("Can't load video %s: %+v", post.Graphql.ShortcodeMedia.Shortcode, err)
|
||||
continue
|
||||
}
|
||||
log.Printf("Loaded video %s, location %s!", post.Media.Code, uname+ext)
|
||||
log.Printf("Loaded video %s, location %s!", post.Graphql.ShortcodeMedia.Shortcode, uname+ext)
|
||||
var IT database.Item
|
||||
IT.UserID = US.ID
|
||||
IT.Service = database.Instagram
|
||||
|
@ -82,23 +82,23 @@ func iterList(list *InstagramListResponse) string {
|
|||
}
|
||||
IT.IsVideo = true
|
||||
IT.Path = uname + ext
|
||||
IT.OriginalID = post.Media.Code
|
||||
IT.OriginalID = post.Graphql.ShortcodeMedia.Shortcode
|
||||
database.Db.Create(&IT)
|
||||
} else {
|
||||
log.Printf("Found picture %s from %s", post.Media.Code, post.Media.Owner.Username)
|
||||
name, uname := ImageNameGenerator(post.Media.Code)
|
||||
res, err := GetHTTPResource(post.Media.DisplaySrc)
|
||||
log.Printf("Found picture %s from %s", post.Graphql.ShortcodeMedia.Shortcode, post.Graphql.ShortcodeMedia.Owner.Username)
|
||||
name, uname := ImageNameGenerator(post.Graphql.ShortcodeMedia.Shortcode)
|
||||
res, err := GetHTTPResource(post.Graphql.ShortcodeMedia.DisplayURL)
|
||||
if err != nil {
|
||||
log.Printf("Can't load picture %s: %+v", post.Media.Code, err)
|
||||
log.Printf("Can't load picture %s: %+v", post.Graphql.ShortcodeMedia.Shortcode, err)
|
||||
continue
|
||||
}
|
||||
defer res.Body.Close()
|
||||
ext, err := DownloadMedia(res.Body, name, false)
|
||||
if err != nil {
|
||||
log.Printf("Can't load picture %s: %+v", post.Media.Code, err)
|
||||
log.Printf("Can't load picture %s: %+v", post.Graphql.ShortcodeMedia.Shortcode, err)
|
||||
continue
|
||||
}
|
||||
log.Printf("Loaded picture %s, location %s!", post.Media.Code, uname+ext)
|
||||
log.Printf("Loaded picture %s, location %s!", post.Graphql.ShortcodeMedia.Shortcode, uname+ext)
|
||||
var IT database.Item
|
||||
IT.UserID = US.ID
|
||||
IT.Service = database.Instagram
|
||||
|
@ -109,7 +109,7 @@ func iterList(list *InstagramListResponse) string {
|
|||
}
|
||||
IT.IsVideo = false
|
||||
IT.Path = uname + ext
|
||||
IT.OriginalID = post.Media.Code
|
||||
IT.OriginalID = post.Graphql.ShortcodeMedia.Shortcode
|
||||
database.Db.Create(&IT)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue