Closed Mofiqul closed 1 year ago
At a glance, the code looks correct to me. That error usually occurs if there is no credential provided. Try to manually pull a token to make sure there is not issues going on with that:
tok, err := creds.TokenSource.Token()
if err != nil {
log.Fatal(err)
}
@codyoss - I tried the your code and got the token as expected. So I have changed my code to
svc, err := playcustomapp.NewService(ctx, option.WithTokenSource(creds.TokenSource))
if err != nil {
log.Printf("Failed to create Custom App Service: %v", err)
return err
}
But still having the same issue.
Hmmm I am not sure in that case. Have you followed all of the step on https://developers.google.com/android/work/play/custom-app-api/get-started ? Whatever the issue, I believe it to be unique to this api and/or the play apis in general. I am more familiar with the cloud apis so I am not a great help here. You may have better luck reaching out and asking for support from the play side of things -- all of these libraries are autogenerated based on a spec and I don't believe this is an issue with the library itself, but rather something with the credential that is being used in this instance.
The only other suggestion I would have to try is you could try using an apikey instead with https://pkg.go.dev/google.golang.org/api/option#WithAPIKey
@codyoss - I've already attempted using the API Key approach, but unfortunately, I haven't had any success with that method either.
Hmmm I am not sure in that case. Have you followed all of the step on https://developers.google.com/android/work/play/custom-app-api/get-started ? Whatever the issue, I believe it to be unique to this api and/or the play apis in general. I am more familiar with the cloud apis so I am not a great help here. You may have better luck reaching out and asking for support from the play side of things -- all of these libraries are autogenerated based on a spec and I don't believe this is an issue with the library itself, but rather something with the credential that is being used in this instance.
Yes. I did everything according to that documentation.
I am not sure than. If you have a support contract I suggest opening up a ticket and/or you may have better luck through the play/android support channels of communication.
@Mofiqul Hello, I am facing the same issue while uploading app bundle using https://developers.google.com/android-publisher/api-ref/rest/v3/edits.bundles/upload API, in my case I am able to hit https://developers.google.com/android-publisher/api-ref/rest/v3/edits/insert API successfully. have you able to resolve your issue ?
Edit: I have tried option.WithTokenSource(creds.TokenSource) but I am seeing a very strange and random behaviour. It is sometimes working and most of the time giving the same error.
any help will be appreciated. @codyoss @Mofiqul
@codyoss @Mofiqul @entombedvirus any update??
My advice is the same as my last comment on this issue: "If you have a support contract I suggest opening up a ticket and/or you may have better luck through the play/android support channels of communication." I don't believe there is an issue on the generated client side, but rather this is a usability of the service/ setup issue.
@Mofiqul have you resolved it?
@harsh-im - My problem was playcustomapp
not androidpublisher
.
const (
packageName = "com.example.app"
)
func Publish(bundlePath string) error {
ctx := context.Background()
data, err := ioutil.ReadFile("path/to/service-account.json"))
if err != nil {
log.Fatalf("Failed to read service account key: %v", err)
}
creds, err := google.CredentialsFromJSON(ctx, data, androidpublisher.AndroidpublisherScope)
if err != nil {
log.Fatalf("Failed to create credentials: %v", err)
}
svc, err := androidpublisher.NewService(ctx, option.WithCredentials(creds))
if err != nil {
log.Fatalf("Failed to create AndroidPublisher service: %v", err)
}
editResponse, err := svc.Edits.Insert(packageName, nil).Do()
if err != nil {
log.Fatalf("Failed to create edit: %v", err)
}
fmt.Printf("Edit created successfully. Edit ID: %s\n", editResponse.Id)
bundleFile, err := os.Open(bundlePath) // Replace with the APK or App Bundle file path
uploadResponse, err := svc.Edits.Apks.Upload(packageName, editResponse.Id).Media(bundleFile).Do()
if err != nil {
log.Fatalf("Failed to upload APK/App Bundle: %v", err)
}
fmt.Printf("APK/App Bundle uploaded successfully. Version code: %d\n", uploadResponse.VersionCode)
_, err = svc.Edits.Commit(packageName, editResponse.Id).Do()
if err != nil {
log.Fatalf("Failed to commit changes: %v", err)
}
fmt.Println("Changes committed successfully. App published!")
return nil
}
This is how I made it work for me, but the downside is that you have to publish the app manually at least once.
Check the expo doc here
@Mofiqul @codyoss Thank you for the reply. I was doing the same as you have suggested but still I was getting 401 error (sometimes it was working as I mentioned previously) as a workaround I added a 1 minute sleep timer after the Insert Edit API & then it was working fine.
i am seeing the same issue Error 401: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project., unauthorized can anyone help us to fix this issue tried all possible ways
I have tried the following code.
Received Error:
I have created the service account and granted permission as documented. Can someone help me with what am I doing wrong.