SocialApi SDK Wrappers - B4A Single-Sign-On with multiple providers

Douglas Farias

Expert
Licensed User
Longtime User
B4X:
AddApplicationText(
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/app_id"/>
      <activity
        android:name="com.facebook.LoginActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
        android:label="$LABEL$"/>)

this works with facebook i have added .Fullscreen on the android:theme="@android:style/Theme.Translucent.NoTitleBar
now is fullscrenn when u click login with facebook

but google? *-*
 

Douglas Farias

Expert
Licensed User
Longtime User
really no problem this is not important for google, for the facebook this code works fine =)
its only a question to knowledge xD

thx man
 

Douglas Farias

Expert
Licensed User
Longtime User
@Periklis Koutsogiannis
how can i get user profile photo from google and face?
i m trying to get
Log(Common.Facebook.GetPhoto.Map.Get("url"))

but give me error *-*
 

Douglas Farias

Expert
Licensed User
Longtime User

Douglas Farias

Expert
Licensed User
Longtime User
B4X:
Log(Common.Facebook.GetPhoto.Map.Get("url"))
= null

like this
B4X:
/* make the API call */
new Request(
    session,
    "/me/picture",
    null,
    HttpMethod.GET,
    new Request.Callback() {
        public void onCompleted(Response response) {
            /* handle the result */
        }
    }
).executeAsync();

i need send the params

B4X:
Bundle params = new Bundle();
params.putBoolean("redirect", false);
params.putString("height", "200");
params.putString("type", "normal");
params.putString("width", "200");
/* make the API call */
new Request(
    session,
    "/me/picture",
    params,
    HttpMethod.GET,
    new Request.Callback() {
        public void onCompleted(Response response) {
            /* handle the result */
        }
    }
).executeAsync();
 

Douglas Farias

Expert
Licensed User
Longtime User
i think the problem is the (my map)

(MyMap) {id=112847041627280480255, verified=false, organizations=[{type=work, title=Desenvolvedor, name=Vallow Development, primary=true}], name=(MyMap) {familyName=Vallow, givenName=Douglas}, circledByCount=1, gender=male, image=(MyMap) {url=https://lh3.googleusercontent.com/-tJZ5NYssgDw/AAAAAAAAAAI/AAAAAAAAABA/5XgqhqZO1Go/photo.jpg?sz=50}, isPlusUser=true, language=pt_BR, displayName=Douglas Vallow, objectType=person, url=https://plus.google.com/112847041627280480255, ageRange=(MyMap) {min=21}, email=[email protected]}

note in the name have (MyMap)
image=(MyMap)

in google and facebook have this problem

here a small example
B4X:
    map1 = Common.GooglePlus.Me
    map2 = map1.Get("name") 
    log(map2)
    lala = map2.Get("givenName")  'ERROR ON THIS LINE lala is a string


log of map2 = (Map) (MyMap) {familyName=Vallow, givenName=Douglas}

i cant get the value of maps on string
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Hola @Douglas Farias. Thanks for reporting the bugs. Map object issues fixed in 2.51

Download the latest package and you are ok :D

For facebook:
B4X:
'https://developers.facebook.com/docs/graph-api/reference/v2.0/user/picture
Dim Result As FacebookResult = Facebook.Get("me/picture", "redirect=false&return=picture.height(200).width(200)")

Dim ImageData As Map = Result.Map.Get("data")

Dim ImageUrl As String = ImageData.Get("url")
Log(ImageUrl)

Dim ImageIsSilhouette As String = ImageData.Get("is_silhouette")
Log(ImageIsSilhouette)

For googleplus:
B4X:
Dim Name As Map = GooglePlus.Me.Get("name")
Dim FamilyName As String = Name.Get("familyName")
Log(FamilyName)

Dim Image As Map = GooglePlus.Me.Get("image")
Dim ImageUrl As String = Image.Get("url")
Log(ImageUrl)
 
Last edited:

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Update: 2.51
  • [SocialApi] Fixed: Map object fixes that prevented proper access to Result.Map
  • [VkProvider] Added: Login permissions scopes: VkProvider.Login(Array as String(VkProvider.Constants.Permissions.FRIENDS))
  • [TwitterProvider] Added: Force always ask credentials parameter (boolean) in method TwitterProvider.Login
 

Douglas Farias

Expert
Licensed User
Longtime User
@Periklis Koutsogiannis
man i m trying to understand this here look

in my 2 activitys i have AND 1 Code Module with name Social



SOCIAL
B4X:
Sub Process_Globals
    Dim Facebook As FacebookProvider
    Dim GooglePlus As GooglePlusProvider
End Sub




MAIN

B4X:
Sub Globals
Dim ThisActivity As SocialApiActivity
End Sub

Sub Activity_Resume
    ThisActivity.InitializeAndBind(Array As SocialApiProvider (Social.Facebook, Social.GooglePlus), "Provider")
End Sub


'OK 2 BUTTONS LOGIN WITH FACE AND GOOGLE CALLING THE SOCIAL

Sub imgface_Click
    Social.Facebook.Login(Null) '<CALL THE SOCIAL.
End Sub

Sub imggoogle_Click
    Social.GooglePlus.Login '<CALL THE SOCIAL.
End Sub

'LATER I HAVE THIS


'WHAT THIS MAKE? ITS TAKE THE USER IF FROM GOOGLE OR FACE AND MAKE A SELECT ON THE DB TO CHECK IF USER
'ALREADY IS REGISTERED, IF YES STARTACTVITY(telaprincipal) ELSE NOT IS REGISTERED STARTACTVITY(completacadastro)

Sub Provider_Connected (Provider As SocialApiProvider)

If Provider Is FacebookProvider Then
    Social.Facebook = Provider
       
    If Not(Social.Facebook.HasPermission(Social.Facebook.Constants.Permissions.Email)) Then
    Social.Facebook.RequestReadPermissions(Array As String (Social.Facebook.Constants.Permissions.Email,Social.Facebook.Constants.Permissions.USER_LOCATION))
    End If
    Try
    idsocial = Social.Facebook.User.Id
    redesocial = "facebook"
    confereusuario
    Catch
    Social.Facebook.Logout
    Msgbox("Ocorreu um erro ao buscar seus dados!","Click Fight")
    End Try   
End If


If Provider Is GooglePlusProvider Then
    Social.GooglePlus = Provider
   
    Try
    idsocial = Social.GooglePlus.User.Id
    redesocial = "google"
    confereusuario
    Catch
    Social.GooglePlus.Logout
    Msgbox("Ocorreu um erro ao buscar seus dados!","Click Fight")
    End Try
End If
End Sub


Sub Provider_Failed (Provider As SocialApiProvider)
    If Msgbox2("Provider '" & Provider.Type & "' failed to actualize your details."&CRLF&CRLF&"Retry?", Provider.Type & ": Error", "Yes", "No", "", Null) = DialogResponse.POSITIVE Then
        Provider.Retry
    End If
End Sub


ok for now working fine nut now on the next activity is the problem


COMPLETACADASTRO

B4X:
'again
Sub Globals
    Private ThisActivity As SocialApiActivity
End Sub

Sub Activity_Resume
 ThisActivity.InitializeAndBind(Array As SocialApiProvider (Social.Facebook, Social.GooglePlus), "Provider")
End Sub

'AND HERE IS THE PROBLEM
'I GET THE USER INFO TO MAKE A INSERT ON THE DB BUT PROVIDER IS EVER FACEBOOK
'I CAN LOGIN WITH GOOGLE  BUT IN THIS ACITIVITY IS EVER If (Provider Is FacebookProvider) Then EVER
'I M NOT LOGGED IN ON FACEBOOK TOO AND IS PROVIDER FACEBOOK HERE TOO


Sub Provider_Event (Provider As SocialApiProvider)

    If (Provider Is GooglePlusProvider) Then
    Try
    idsocial = Social.GooglePlus.User.Id
    Msgbox("lala","lala")
    Catch
    Social.GooglePlus.Logout
    Msgbox("Ocorreu um erro ao buscar seus dados!","Click Fight")
    End Try
    End If
   
   
   
   
    If (Provider Is FacebookProvider) Then
    Try
    redesocial = "facebook"
    idsocial = Social.Facebook.user.Id
    sexo = Social.Facebook.Me.Get("gender")
    cn = Social.Facebook.Me.Get("name")
    fn = Social.Facebook.Me.Get("first_name")
    ln = Social.Facebook.Me.Get("last_name")
    locale = Social.Facebook.Me.Get("locale")
    username = Social.Facebook.Me.Get("username")
    'pega email
    Email = Social.Facebook.user.Email
    edemail.Text = Email
    'pega cidade
    'cidade = Common.Facebook.Me.Get("location")
    'edcidade.Text = cidade
    Catch
    Msgbox("Você deve autorizar o Click Fight de obter seus dados cadastrais! Efetue o login novamente!","Click Fight")
    CallSubDelayed(Main,"desatualizarface")
    End Try
    End If
   
End Sub


Sub Provider_Disconnected (Provider As SocialApiProvider)
End Sub

Sub Provider_Failed (Provider As SocialApiProvider)
    If Msgbox2("Não foi possível logar utilizando o '" & Provider.Type & "' Ocorreu uma falha ao obter os dados pessoas da conta."&CRLF&CRLF&" Tentar Novamente!", "Click Fight", "OK", "Cancelar", "", Null) = DialogResponse.POSITIVE Then
        Provider.Retry
    End If
End Sub

why this?
i m using social.face or google

but on this activity start facebook ever
i make
Sub Provider_Event (Provider As SocialApiProvider)
msgbox(Provider,"teste")

and this is ever facebook *-*
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
The Provider_Event should only be used for UI updating.

You should use Provider_Connected and Provider_Disconnected events for checking if provider is connected or disconnected.

What do your mean with "but on this activity start facebook ever" ?
 
Last edited:

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Btw, in the second activity you do not handle Provider_Connected like you do in the main activity. Instead, you are using the Provider_Event
 

Douglas Farias

Expert
Licensed User
Longtime User
The Provider_Event should only be used for UI updating.
You should user Provider_Connected and Provider_Disconnected events for checking if provider is connected or disconnected.

What do your mean with "but on this activity start facebook ever" ?

when i start the COMPLETACADASTRO
provider is ever facebook, never is google
i m using Provider_Event because i m already login on the main
in this activity i want only get the values
if is google
get google id, gender etc
and make a query to register

if is face
same

but the problem is provider is facebook only
if i login with google and start this activity the provider is = facebook o_O
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Yes because the event flow continues after the

B4X:
If (Provider Is GooglePlusProvider) Then ...
block

and evaluates the
B4X:
If (Provider Is FacebookProvider) Then ...
block.

That means the always the last block will be evaluated. Your program logic is not correct.

As mentioned you should always use the Provider_Connected event to do things for any connected provider and NOT the Provider_Event like you do in your main activity.

The Provider_Event gets ALL events. Disconnected as well.
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
If you want to have 1 connected provider at a time, check the socialapi\multiple\samples\sample1 sample.

If you want to have more than 1 connected providers at a time, check the socialapi\multiple\samples\sample2 sample.

Always use the Events like in the samples.
 
Top