Reactjs 成功登录后回调URI不工作
我正在为Spotify SDK使用React原生npm包。应用程序在登录页面和隐私协议策略页面中进展顺利,单击“接受”后,应用程序会思考一秒钟,然后使用Spotify页面返回到原始登录页面,而不是进入我的视频页面 我的想法是我的回调url没有通过Spotify正确设置?这是我的密码:Reactjs 成功登录后回调URI不工作,reactjs,react-native,spotify,Reactjs,React Native,Spotify,我正在为Spotify SDK使用React原生npm包。应用程序在登录页面和隐私协议策略页面中进展顺利,单击“接受”后,应用程序会思考一秒钟,然后使用Spotify页面返回到原始登录页面,而不是进入我的视频页面 我的想法是我的回调url没有通过Spotify正确设置?这是我的密码: import React, { Component } from 'react'; import { ActivityIndicator, Alert, StyleSheet, Te
import React, { Component } from 'react';
import {
ActivityIndicator,
Alert,
StyleSheet,
Text,
TouchableHighlight,
View
} from 'react-native';
import { NavigationActions } from 'react-navigation';
import Spotify from 'rn-spotify-sdk';
class SpotifyLogin extends Component
{
static navigationOptions = {
header: null
};
constructor()
{
super();
this.state = {spotifyInitialized: false};
this.spotifyLoginButtonWasPressed = this.spotifyLoginButtonWasPressed.bind(this);
}
goToPlayer()
{
const navAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Video'})
]
});
this.props.navigation.dispatch(navAction);
}
componentDidMount()
{
// initialize Spotify if it hasn't been initialized yet
if(!Spotify.isInitialized())
{
// initialize spotify
var spotifyOptions = {
"clientID":"0adddabe05f64f499e3778f300d77d51",
"sessionUserDefaultsKey":"SpotifySession",
"redirectURL":"uncvrdapp://auth",
"scopes":["user-read-private", "playlist-read", "playlist-read-private", "streaming"],
};
Spotify.initialize(spotifyOptions).then((loggedIn) => {
// update UI state
this.setState({spotifyInitialized: true});
// handle initialization
if(loggedIn)
{
this.goToPlayer();
}
}).catch((error) => {
Alert.alert("Error", error.message);
});
}
else
{
// update UI state
this.setState((state) => {
state.spotifyInitialized = true;
return state;
});
// handle logged in
if(Spotify.isLoggedIn())
{
this.goToPlayer();
}
}
}
spotifyLoginButtonWasPressed()
{
// log into Spotify
Spotify.login().then((loggedIn) => {
if(loggedIn)
{
// logged in
this.goToPlayer();
}
else
{
// cancelled
}
}).catch((error) => {
// error
Alert.alert("Error", error.message);
});
}
render()
{
if(!this.state.spotifyInitialized)
{
return (
<View style={styles.container}>
<ActivityIndicator animating={true} style={styles.loadIndicator}>
</ActivityIndicator>
<Text style={styles.loadMessage}>
Loading...
</Text>
</View>
);
}
else
{
return (
<View style={styles.container}>
<Text style={styles.greeting}>
Hey! You! Log into your spotify
</Text>
<TouchableHighlight onPress={this.spotifyLoginButtonWasPressed} style={styles.spotifyLoginButton}>
<Text style={styles.spotifyLoginButtonText}>Log into Spotify</Text>
</TouchableHighlight>
</View>
);
}
}
}
export default SpotifyLogin;
接下来是我的Spotify开发者控制台,显示我的回调URI
它们是一样的。我哪里做错了,为什么它不能像我期望的那样进入视频页面?谢谢大家! 如聊天中所述。这个问题可以通过将它们转换为异步方法来解决
componentDidMount()
{
// initialize Spotify if it hasn't been initialized yet
if(!Spotify.isInitializedAsync())
{
// initialize spotify
var spotifyOptions = {
"clientID":"0adddabe05f64f499e3778f300d77d51",
"sessionUserDefaultsKey":"SpotifySession",
"redirectURL":"uncvrdapp://auth",
"scopes":["user-read-private", "playlist-read", "playlist-read-private", "streaming"],
};
Spotify.initialize(spotifyOptions).then((loggedIn) => {
// update UI state
this.setState({spotifyInitialized: true});
// handle initialization
if(loggedIn)
{
this.goToPlayer();
}
}).catch((error) => {
Alert.alert("Error", error.message);
});
}
else
{
// update UI state
this.setState((state) => {
state.spotifyInitialized = true;
return state;
});
// handle logged in
if(Spotify.isLoggedInAsync()) // <-- here
{
this.goToPlayer();
}
}
}
spotifyLoginButtonWasPressed()
{
// log into Spotify
Spotify.login().then((loggedIn) => {
if(loggedIn)
{
// logged in
this.goToPlayer();
}
else
{
// cancelled
}
}).catch((error) => {
// error
Alert.alert("Error", error.message);
});
}
您是否有任何错误?请在componentDidMount if语句中输入console.log loggedIn,在else语句中输入Spotify.isLoggedIn。@HungrySoul我刚刚尝试在chrome中输入console.logging和读取输出,但我收到了以下错误:不变冲突:chrome不支持在本机模块上调用同步方法。考虑提供其他方法来在调试模式下公开此方法,例如提前曝光常数。@ PrimthHavaIDya,我似乎不能使用Chrome中的COUNSOL.Logo调试,请参阅上面的响应……HMMCAN,您可以尝试在IF语句中替换THE.GotoPosit与控制台语句。你确定你的设备上没有出现同样错误的红屏吗?嘿,对不起,反应太晚了,但我是这个软件包的开发者。在不等待结果承诺的情况下调用isLoggedInAsync将始终计算为true,因为结果是承诺而不是布尔值。您应该等待isLoggedInAsync的结果