gpt4 book ai didi

javascript - 错误 : ReferenceError: getUnreadEmails is not defined

转载 作者:行者123 更新时间:2023-11-30 19:40:03 26 4
gpt4 key购买 nike

当我在 App.js 中调用方法 getNumberOfUnreadEmails 时,请问我有这个错误:YellowBox.js:67 Possible Unhandled Promise Rejection (id: 0):错误:ReferenceError:未定义 getUnreadEmails错误:ReferenceError:未定义 getUnreadEmails 在 blob:http://localhost:8081/16f9ab34-0ee8-4ee2-8319-83df5fb4878a:102968:19 在 tryCallOne(blob:http://localhost:8081/16f9ab34-0ee8-4ee2-8319-83df5fb4878a:31155:14) 在 blob:http://localhost:8081/16f9ab34-0ee8-4ee2-8319-

期待:给我未读消息的数量

AzureInstance.js


export default class AzureInstance {
constructor(credentials) {
this.authority = 'https://login.microsoftonline.com/common';
this.authorize_endpoint = '/oauth2/v2.0/authorize';
this.redirect_uri = 'https://login.microsoftonline.com/common/oauth2/nativeclient';
this.token_endpoint ='/oauth2/v2.0/token';
this.client_id = credentials.client_id;
this.client_secret = credentials.client_secret;
this.scope = credentials.scope;
this.token = {};

// function binding
this.getConfig = this.getConfig.bind(this);
this.setToken = this.setToken.bind(this);
this.getToken = this.getToken.bind(this);
this.getUserInfo = this.getUserInfo.bind(this);
this.getUnreadEmails=this.getUnreadEmails.bind(this);
this.getNumberOfUnreadEmails=this.getNumberOfUnreadEmails.bind(this);
//this.getRequest=this.getRequest.bind(this);
}

getConfig(){
return {
authority: this.authority,
authorize_endpoint: this.authorize_endpoint,
token_endpoint: this.token_endpoint,
client_id: this.client_id,
client_secret: this.client_secret,
redirect_uri: this.redirect_uri,
scope: this.scope,
}
}

setToken(token){
this.token = token;
}

getToken(){
return this.token;
}
getUserInfo()
{
try{
return this.getRequest("https://graph.microsoft.com/v1.0/me");
}
catch(err){
throw err;
}
}

getNumberOfUnreadEmails()
{
return getUnreadEmails().value.length();
}
getUnreadEmails()
{
try{
return this.getRequest("https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages?$filter=isRead ne true");
}
catch(err){
throw err;
}
}

getRequest(req) {
if (this.token === undefined){
throw new Error("Access token is undefined, please authenticate using Auth first");
}

return fetch(req, {
headers: {
'Authorization': "Bearer " + this.token.accessToken,
}
}).then(response => {
// return blob object
return response.json()
})
.then(response => {
// read blob object back to json
return response
}).catch(err => {
// incase of error reject promise
throw new Error(err);
});
}
}

App.js


import React from 'react';
import {AppRegistry,Text,StyleSheet,Picker} from 'react-native';
import {View} from 'react-native-webview';

import {AzureInstance, AzureLoginView} from '../src/screens/auth/';

// CONSTANT
const CREDENTIAILS = {
client_id: '--------------------------',
client_secret: '--------------------',
scope: 'User.ReadBasic.All Mail.Read offline_access'
};

export default class azureAuth extends React.Component {
constructor(props){
super(props);
this.state = {
displayName : "Nan",
mail : "",
id : ""
};
this.azureInstance = new AzureInstance(CREDENTIAILS);
this._onLoginSuccess = this._onLoginSuccess.bind(this);
}

_onLoginSuccess(){
this.azureInstance.getUserInfo().then(result => {
console.log(result);
}).catch(err => {
console.log(err);
});
this.azureInstance.getUnreadEmails().then(result =>{
console.log(result);
}).catch(err =>{
console.log(err);
});

this.azureInstance.getNumberOfUnreadEmails().then(result =>{
console.log(result);
}).catch(err =>{
console.log(err);
});
}

render() {
return (
<AzureLoginView
azureInstance={this.azureInstance}
loadingMessage="Requesting access token"
onSuccess={this._onLoginSuccess}
/>
);
}
}

const styles = StyleSheet.create({
container: {
paddingTop: 23
},
baseText: {
fontFamily: 'Cochin',
},
titleText: {
fontSize: 20,
fontWeight: 'bold',
},
});

AppRegistry.registerComponent('azureAuth', () => azureAuth);

最佳答案

我觉得应该是this.getUnreadEmails()

getNumberOfUnreadEmails() {
return this.getUnreadEmails().value.length();
}

让我知道它是否有效!

关于javascript - 错误 : ReferenceError: getUnreadEmails is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55497623/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com