question

堀 涼 avatar image
堀 涼 asked

How to solce "StatusCode:403 The authentication token does not have access to resource"

I am making alexa skill which retreive user's information such as name, phone number, and mail address in alexa developer console.

Although I think I set permissions correctly, add all permissons as explained in here, turn on personalization in alexa developer console, upsServiceClient.getProfileName() retuns error, 'StatusCode:403 The authentication token does not have access to resource'.


Would some one help me, please?


Here's some snippet.

    const PERMISSIONS = [
      'alexa::profile:name:read',
      'alexa::profile:mobile_number:read',
      'alexa::profile:email:read'
    ];

    const { requestEnvelope, serviceClientFactory, responseBuilder } = handlerInput;

    try {
      console.log('try')
      const upsServiceClient = serviceClientFactory.getUpsServiceClient();  
      console.log(upsServiceClient) -> this is output
      console.log(handlerInput.requestEnvelope.context.System.user.accessToken) -> this is output, but undefined.
      userName = await upsServiceClient.getProfileName();           
      console.log(userName) -> this is not output
      email = await upsServiceClient.getProfileEmail();               
      console.log(email)
 
    const speechText = 'こんにちは!!!!3つの質問に答えることで、食事の栄養バランスのチェックを行うことができます。スタートと言ってください。';
    const aplSample = require('./toplist.json'); //最初に表示される画面
    
      return handlerInput.responseBuilder
      .addDirective({
                 type : 'Alexa.Presentation.APL.RenderDocument',
                 version: '1.9.0',
                 document: aplSample.document,
                     datasources: aplSample.datasources
             })
      .speak(speechText)
      .reprompt(speechText)
      .getResponse();
      
    } catch (error) {
      if (error.name == 'ServiceError') {
        console.log('ERROR StatusCode:' + error.statusCode + ' ' + error.message);
      }
      return responseBuilder
        .speak('ユーザー情報の利用が許可されていませんアレクサアプリの設定を変更して下さい!!!!!!!!!!!!!')
        .withAskForPermissionsConsentCard(PERMISSIONS)
        .getResponse();
    }
alexadeveloper console
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

堀 涼 avatar image
堀 涼 answered

Checking as much as possible, it seems that upsServiceClient.getProfileName() returns error.

getProfileEmail() works well.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Andy Whitworth avatar image
Andy Whitworth answered

If you don't have an accessToken in your request then the getProfileName() call will fail, as you're experiencing.

Are you 100% sure you granted the required permissions when you enabled the skill ? If you don't grant permissions then the accessToken will be missing.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.