Android Question Email Function - Based on Erels OAuth Mechanism fails in bigger app

DaOel

Member
Licensed User
Longtime User
Hello,
I downloaded the project in erel's tutorial here:


Everything works nicely.
But once I try to implement it in my bigger own project the following problem happens:

My App opens the webview and I need to allow 'SpreadSheet' to send Emails. So I press 'Allow'. But instead of being redirected into the app, there is a blue bar running many times from left to right indicating the request is being processed. (This is normal, it just takes a bit longer than usual.) Unfortunatelly I am then redirected to a google search site finally.
The Email itself was not sent.

It also does not remember my choice to 'Allow' and I will be asked the same process next time.

What might be the problem here?
Thanks!

---update---
I tried to simply register the OAuth Client ID with lowercase project name. --> Later a match was not possible. (because my Project Name contains upper letters)
I renamed my project to lowercase --> it works. However this is a new app then and not an option for me, as my app is already published on Google PlayStore.

This problem is related to this problem (which was solved by changing the scheme name)
This also works for me!
 
Last edited:

DaOel

Member
Licensed User
Longtime User
Perhaps I tried too many times but now it gets stuck here all the time:
Screenshot_20231226-161047_Chrome.jpg


The Code looks as follows:

B4X:
Sub Process_Globals
    Private oauth2 As GoogleOAuth2
End Sub

'[...]

Sub button1_Click
    
    oauth2.Initialize(Me, "oauth2", Starter.ClientId, "https://www.googleapis.com/auth/gmail.send")
    oauth2.CallFromResume(Activity.GetStartingIntent)
        
    oauth2.GetAccessToken
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
    If Success = False Then
        Log("Error accessing account.")
        Return
    End If
    
End Sub
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DaOel

Member
Licensed User
Longtime User
Hey DonManfred,
thanks for looking into it.
I got rid of this Screenshot 'One moment please', by deleting all Oauth Clients again in google play console and create a new one.

However I was not able to solve the other problem with the failing redirect and failing permission as a whole.
In my big app,
I now placed the line
B4X:
oauth2.Initialize(Me, "oauth2", Starter.ClientId, "https://www.googleapis.com/auth/gmail.send")
into Activity_Create

and placed the line
B4X:
oauth2.CallFromResume(Activity.GetStartingIntent)
into Activity_Resume

The problem remains.

In my big app the link is:

While in the small sample App the redirect looks like this:

So the links look very similiar to me.

This link is used here:
B4X:
#if B4A
    Dim pi As PhoneIntents
    StartActivity(pi.OpenBrowser(link))


I am very uncertain what the problem might be.
As one project works and the other is not I think a good approach would be to somehow extend the small project until it is similiar to the big project.
However if you have clues what is most likely the problem it could save me a lot of time.
 
Last edited:
Upvote 0

DaOel

Member
Licensed User
Longtime User
I might have found the problem.
After everything was the same on both projects. There was only 1 thing that was different: the project name.

Not sure on which side it is wrong to enter Capital Letters. But perhaps Projects with Capital Letters are not allowed for OAuth Client ID.
b4a.googlecontacts or b4a.test are all small letters and there it works.

-- update --
I tried to simply register the OAuth Client ID with lowercase project name. --> Later a match was not possible. (because my Project Name contains upper letters)

I renamed my project to lowercase --> it works. However this is a new app then and not an option for me, as my app is already published on Google PlayStore.
 
Last edited:
Upvote 0

DaOel

Member
Licensed User
Longtime User
Related Problem:
Changing the Scheme Name is also a solution for me here. :)
 
Upvote 0
Top