@@ -3,7 +3,6 @@ package v22
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "slices"
7
6
8
7
"github.com/justwatch/facebook-marketing-api-golang-sdk/fb"
9
8
)
@@ -29,28 +28,21 @@ func (ps *PageService) SetPageAccessToken(ctx context.Context, pageID string) (c
29
28
}
30
29
31
30
// GetPageBackedInstagramAccounts returns the instagram actor associated with a facebook page.
32
- func (ps * PageService ) GetPageBackedInstagramAccounts (ctx context.Context , pageID string ) (* InstagramUser , error ) {
31
+ func (ps * PageService ) GetInstagramBusinessAccount (ctx context.Context , pageID string ) (* InstagramUser , error ) {
33
32
ctx , err := ps .SetPageAccessToken (ctx , pageID )
34
33
if err != nil {
35
34
return nil , err
36
35
}
37
36
38
37
fpiga := struct {
39
- // Entity in the GraphAPI: IGUser.
40
- ConnectedPageBackedInstagramAccount struct {
41
- Data []InstagramUser `json:"data"`
42
- } `json:"instagram_accounts"`
38
+ InstagramBusinessAccount InstagramUser `json:"instagram_business_account"`
43
39
}{}
44
- err = ps .c .GetJSON (ctx , fb .NewRoute (Version , "/%s" , pageID ).Fields ("instagram_accounts {id,username}" ).String (), & fpiga )
40
+ err = ps .c .GetJSON (ctx , fb .NewRoute (Version , "/%s" , pageID ).Fields ("instagram_business_account {id,username}" ).String (), & fpiga )
45
41
if err != nil {
46
42
return nil , err
47
43
}
48
44
49
- if len (fpiga .ConnectedPageBackedInstagramAccount .Data ) != 1 {
50
- return nil , fmt .Errorf ("could not get consistent page_backed_instagram_accounts data for facebook page with external id %s" , pageID )
51
- }
52
-
53
- res := fpiga .ConnectedPageBackedInstagramAccount .Data [0 ]
45
+ res := fpiga .InstagramBusinessAccount
54
46
if res .ID == "" {
55
47
return nil , fmt .Errorf ("could not get page_backed_instagram_accounts ID for facebook page with external id %s" , pageID )
56
48
}
@@ -97,31 +89,17 @@ func (ps *PageService) GetInstagramUsers(ctx context.Context, businessID string)
97
89
return res , nil
98
90
}
99
91
100
- func (aas * PageService ) ListIGUsers (ctx context.Context ) ([]IGUser , error ) {
101
- res := []IGUser {}
102
- rb := fb .NewRoute (Version , "/me/accounts " ).Limit (1000 ).Fields ("id" , "name" , "instagram_business_account" , "connected_instagram_account" )
92
+ func (aas * PageService ) ListIGUsers (ctx context.Context ) ([]InstagramUser , error ) {
93
+ res := []InstagramUser {}
94
+ rb := fb .NewRoute (Version , "/me/instagram_accounts " ).Limit (1000 ).Limit ( 1000 ). Fields (instagramUserFields ... )
103
95
err := aas .c .GetList (ctx , rb .String (), & res )
104
96
if err != nil {
105
97
return nil , err
106
98
}
107
- res = slices .DeleteFunc (res , func (i IGUser ) bool {
108
- return i .InstagramBusinessAccount .ID == "" && i .ConnectedInstagramAccount .ID == ""
109
- })
110
99
111
100
return res , nil
112
101
}
113
102
114
- type IGUser struct {
115
- Name string `json:"name"`
116
- InstagramBusinessAccount struct {
117
- ID string `json:"id"`
118
- } `json:"instagram_business_account"`
119
- ConnectedInstagramAccount struct {
120
- ID string `json:"id"`
121
- } `json:"connected_instagram_account"`
122
- ID string `json:"id"`
123
- }
124
-
125
103
// Get returns a single page.
126
104
func (ps * PageService ) Get (ctx context.Context , id string ) (* Page , error ) {
127
105
res := & Page {}
@@ -138,7 +116,7 @@ func (ps *PageService) Get(ctx context.Context, id string) (*Page, error) {
138
116
return res , nil
139
117
}
140
118
141
- // GetInstagramUser returns a single instagram actor .
119
+ // GetInstagramUser returns a single instagram user .
142
120
func (ps * PageService ) GetInstagramUser (ctx context.Context , id string ) (* InstagramUser , error ) {
143
121
res := & InstagramUser {}
144
122
route := fb .NewRoute (Version , "/%s" , id ).Fields (instagramUserFields ... )
@@ -161,7 +139,7 @@ type Page struct {
161
139
GlobalBrandPageName string `json:"global_brand_page_name"`
162
140
}
163
141
164
- // InstagramUser represents an instagram actor.
142
+ // InstagramActor represents an instagram actor.
165
143
type InstagramUser struct {
166
144
ID string `json:"id"`
167
145
Username string `json:"username"`
0 commit comments