无法使用Google Photo API创建相册

时间:2018-10-22 05:34:09

标签: android google-authentication google-photos-api

尝试使用Google Photo API创建新相册时遇到此错误:

com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Authentication information is missing.

这里是带范围的认证(用Kotlin编写):

val scopes = arrayOf(
            Scope("https://www.googleapis.com/auth/photoslibrary.sharing"),
            Scope("https://www.googleapis.com/auth/photoslibrary.appendonly"),
            Scope("https://www.googleapis.com/auth/photoslibrary.readonly"))


 override fun executeGoogleAuth() {
    if (!GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this), *scopes)) {
        GoogleSignIn.requestPermissions(
                this,
                RC_SIGN_IN,
                GoogleSignIn.getLastSignedInAccount(this),
                *scopes)
    }
}

身份验证成功,然后我的应用转到下一个创建相册的功能:

private fun createAlbum(albumName: String): Album {
        val inputStream = context.resources.openRawResource(R.raw.default_credential)
        val credentials = ServiceAccountCredentials.fromStream(inputStream)
        val settings = PhotosLibrarySettings.newBuilder()
                .setCredentialsProvider(FixedCredentialsProvider.create(credentials))
                .build()
        val photosLibraryClient = PhotosLibraryClient.initialize(settings)
        val createdAlbum = photosLibraryClient.createAlbum(albumName)
        inputStream.close()
        return createdAlbum
    }

此行引发了异常:

  

val createdAlbum = photosLibraryClient.createAlbum(albumName)

有人可以告诉我这里出了什么问题吗?提前致谢!

0 个答案:

没有答案