@@ -19,23 +19,23 @@ export interface OAuthInstagramConfig {
1919 clientSecret ?: string
2020 /**
2121 * Instagram OAuth Scope
22- * @default [ 'user_profile ' ]
22+ * @required [ 'business_basic ' ]
2323 * @see https://developers.facebook.com/docs/instagram-basic-display-api/overview#permissions
24- * @example [ 'user_profile ', 'user_media ' ],
24+ * @example [ 'business_basic ', 'business_manage_messages ' ],
2525 */
26- scope ?: string [ ]
26+ scope ?: ( 'business_basic' | 'business_content_publish' | 'business_manage_comments' | 'business_manage_messages' ) [ ]
2727
2828 /**
2929 * Instagram OAuth User Fields
3030 * @default [ 'id', 'username'],
3131 * @see https://developers.facebook.com/docs/instagram-basic-display-api/reference/user#fields
32- * @example [ 'id', 'username', 'account_type', 'media_count ' ],
32+ * @example [ 'id', 'username', 'user_id', ' account_type', 'profile_picture_url ' ],
3333 */
34- fields ?: string [ ]
34+ fields ?: ( 'id' | 'user_id' | 'username' | 'name' | 'account_type' | 'profile_picture_url' | 'followers_count' | 'follows_count' | 'media_count' ) [ ]
3535
3636 /**
3737 * Instagram OAuth Authorization URL
38- * @default 'https://api .instagram.com/oauth/authorize'
38+ * @default 'https://www .instagram.com/oauth/authorize'
3939 */
4040 authorizationURL ?: string
4141
@@ -64,19 +64,28 @@ export function defineOAuthInstagramEventHandler({
6464} : OAuthConfig < OAuthInstagramConfig > ) {
6565 return eventHandler ( async ( event : H3Event ) => {
6666 config = defu ( config , useRuntimeConfig ( event ) . oauth ?. instagram , {
67- scope : [ 'user_profile ' ] ,
68- authorizationURL : 'https://api .instagram.com/oauth/authorize' ,
67+ scope : [ 'business_basic ' ] ,
68+ authorizationURL : 'https://www .instagram.com/oauth/authorize' ,
6969 tokenURL : 'https://api.instagram.com/oauth/access_token' ,
7070 authorizationParams : { } ,
7171 } ) as OAuthInstagramConfig
7272
73- const query = getQuery < { code ?: string , error ?: string } > ( event )
73+ const query = getQuery < {
74+ code ?: string
75+ error ?: string
76+ error_reason ?: string
77+ error_description ?: string
78+ } > ( event )
7479
7580 if ( query . error ) {
7681 const error = createError ( {
7782 statusCode : 401 ,
7883 message : `Instagram login failed: ${ query . error || 'Unknown error' } ` ,
79- data : query ,
84+ data : {
85+ error : query . error ,
86+ error_reason : query . error_reason ,
87+ error_description : query . error_description ,
88+ } ,
8089 } )
8190 if ( ! onError ) throw error
8291 return onError ( event , error )
@@ -96,7 +105,7 @@ export function defineOAuthInstagramEventHandler({
96105 withQuery ( config . authorizationURL as string , {
97106 client_id : config . clientId ,
98107 redirect_uri : redirectURL ,
99- scope : config . scope . join ( ' ' ) ,
108+ scope : config . scope . join ( ) ,
100109 response_type : 'code' ,
101110 } ) ,
102111 )
@@ -120,10 +129,10 @@ export function defineOAuthInstagramEventHandler({
120129 // TODO: improve typing
121130
122131 config . fields = config . fields || [ 'id' , 'username' ]
123- const fields = config . fields . join ( ',' )
132+ const fields = config . fields . join ( )
124133
125134 const user = await $fetch (
126- `https://graph.instagram.com/v20 .0/me?fields=${ fields } &access_token=${ accessToken } ` ,
135+ `https://graph.instagram.com/v21 .0/me?fields=${ fields } &access_token=${ accessToken } ` ,
127136 )
128137
129138 if ( ! user ) {
0 commit comments