react-native-spotify-remote icon indicating copy to clipboard operation
react-native-spotify-remote copied to clipboard

TypeError: null is not an object (evaluating 'react_native_1.NativeModules.RNSpotifyRemoteAuth.authorize')

Open DrBuzzzz opened this issue 3 years ago • 2 comments

Hello, I tried to install and use this package as it seems to be perfect for my usecase. I did everything described in the docs and I also tried the manual linking steps for android but I still get this error. It's probably important to know that I use expo but a bare workflow. I saw this issue, but he used an expo managed workflow. My React Native version is 0.69.3. My code looks exactly the same as described in the docs:

import React, { useContext, useEffect } from "react";

import { Button, Text, View, StyleSheet } from "react-native";

import { ThemeContext } from "../context/context";
import { lightTheme, darkTheme } from "../styles/themes";

import {
  auth as SpotifyAuth,
  remote as SpotifyRemote,
  ApiScope,
} from "react-native-spotify-remote";

// Api Config object, replace with your own applications client id and urls
const spotifyConfig = {
  clientID: "0f080...",
  redirectURL: "exp://192.168.10.35:19000/--/callback",
  tokenRefreshURL: "SPOTIFY_TOKEN_REFRESH_URL",
  tokenSwapURL: "SPOTIFY_TOKEN_SWAP_URL",
  scopes: [ApiScope.AppRemoteControlScope, ApiScope.UserFollowReadScope],
};

export default function MusicScreen({ navigation }) {
  const { getTheme } = useContext(ThemeContext);
  const theme = getTheme();

  async function playEpicSong() {
    try {
      const session = await SpotifyAuth.authorize(spotifyConfig);
      await SpotifyRemote.connect(session.accessToken);
      await SpotifyRemote.playUri("spotify:track:6IA8E2Q5ttcpbuahIejO74");
      await SpotifyRemote.seek(58000);
    } catch (err) {
      console.error("Couldn't authorize with or connect to Spotify", err);
    }
  }

  return (
    <View
      style={[
        styles.container,
        theme === "light" ? lightTheme.container : darkTheme.container,
      ]}
    >
      <Button title="Play Epic Song" onPress={() => playEpicSong()} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

I hope you can help me!

DrBuzzzz avatar Aug 04 '22 08:08 DrBuzzzz

Did you run pod install in your iOS directory?

JoeToeniskoetter avatar Aug 09 '22 11:08 JoeToeniskoetter

Oh sorry, I forgot to mention that I'm building for Android.

DrBuzzzz avatar Aug 10 '22 13:08 DrBuzzzz