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

Douglas Farias

Expert
Licensed User
Longtime User
hmmm but how to start automatic this on the COmPLETACADASTRO
i m want to login in main and later send user to next activity and get the profile infos in the COmPLETACADASTRO
without any click to connect because user already click on the main

Provider_Connected use click no ?
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Sorry but I do not understand. What do you mean with "use click"?

You have to clearly define your app flow and use:
  • Provider_Event for updating your UI since it gets fired when connected,disconnected,ready events for all providers
  • Provider_Connected to handle CONNECT events
  • Provider_Disconnected to handle DISCONNECT events
Unfortunately, since I am not fully aware of your program logic, it is very difficult to answer questions that are related to it. :(
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Since you catch the Provider_Connected event, you know what provider is connected. From that point, you can define your app flow accordingly.
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
You catch the Provider_Connected in your main activity, and in the second activity, you don't need to have any provider events since your main activity has already set the active provider.

You only need to have events only in activities that may change the status of the provider (logout for instance) and redirect them you main activity events.


It is a matter of designing a login flow.
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
For example:

In socialapi\multiple\samples\sample1, in the ConnectWith activity, there is only a Provider_Connected event that catches the provider login, gracefully ends the activity and redirects the event to the main activity.

B4X:
Sub Activity_Resume
    ThisActivity.InitializeAndBind(Social.Providers, "provider")
End Sub

Sub Provider_Connected (Provider As SocialApiProvider)
    CallSubDelayed2(Main, "Provider_Connected", Provider)
    Activity.Finish
End Sub


You can always have an eventless initialization:
B4X:
ThisActivity.InitializeAndBind(Social.Providers, "")
'or
ThisActivity.InitializeAndBindWithNoEvent(Social.Providers)
and
B4X:
FacebookProvider.SetActivity(ThisActivity.Initialize(""))
'or
FacebookProvider.SetActivity(ThisActivity.InitializeWithNoEvent))
 
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
@Periklis Koutsogiannis
hello, I'm doing my last request in this lib.
If you have time, please help me, I will not ask and keep you.
I'm not getting a part, and I do not understand too.

1° can you make a example using all social apis, you conect in the main, and can get.me profile on all anothers activitys
main > activity1 2 3 etc.

i try your examples but i realy dont understant how to make this automatic, i try and try and not sucess.
for exemple

i go use google + facebook login.

when u press on login with google for example , the app go to next activity and get profile automatic and show this on the screen.

if the user log on with face in the main, go to activity 1 or 2 or 3 and show the profile automatic whitout any click at buttons to get profile.

can help me on this? is my last request, I will not disturb you anymore.


2° with facebook how can i download the image of the browser like a sample 4
open the browser to user select the image, if user select one picture, download this to app to load on the imageview

thx again man, sory for question this again but i realy need but i dont understand how *-*
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Hola Douglas.

The sample1 does exactly that.

  1. If you are not connected with any provider, it shows a connect button and the action panel is hidden.
  2. When you press connect, a second activity opens and you login with 1 of the available providers.
  3. When connected, the login activity finishes and returns back to the main activity
  4. There, though the "Social.ActiveProvider", you access the connected provider properties and methods.
  5. When you start the app again, the app will automatically connect to the last used provider and if successful, it will enable the hidden action panel where you can click the available actions and get information through the ActiveProvider properties or specifically cast the ActiveProvider to the actual provider type and access provider specific information.
About the image downloading.

As long as you have the image links (you can check sample4 where the html is being build), you can easily download them by using the code provided in the link below:

http://www.b4x.com/android/forum/th...-simple-way-to-download-images.30875/#content

You can ask as many times you want, I have no problem with that :D
 

Douglas Farias

Expert
Licensed User
Longtime User
@Periklis Koutsogiannis
i found 3 bugs
the google dont call the disconected provider
all anothers call only google no =(

login with all social api´s is ok

1-Google dont call Sub Provider_Disconnected (Provider As SocialApiProvider)
2-Get google picture url have a problem, when u get
https://lh3.googleusercontent.com/-tJZ5NYssgDw/AAAAAAAAAAI/AAAAAAAAABA/5XgqhqZO1Go/photo.jpg?sz=50

all time the image back with ?sz=50 50px

3-sometimes later u conect in the multsample1 and back to main screnn the app close
o_O
 
Last edited:

brelto85

Active Member
Licensed User
Longtime User
I've this scenario:

In my main activity_resume i've added this code line:

B4X:
ThisActivity.InitializeAndBindWithNoEvent(Social.Providers)

My providers (facebook and twitter) are connected and the PublishPost and Tweet methods work properly

The problem is that if i disconnect (from preference activity) and re-connect one of this provider, after call the PublishPost or Tweet methods, get this error:

android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@415219b8 is not valid; is your activity running?

The method PublishPost and Tweet are called from a class
where is the problem?
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Whenever you switch activity, you should always bind the providers to the active activity's SocialApiActivity object in order to pass an active activity handle to the framework.

Check the last part of the error:

android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@415219b8 is not valid; is your activity running?

After you close your preference activity, you land in an another activity. In that activity's Sub Activity_Resume you should bind the providers again.
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
To be more precise, the activity that calls the publish the post and tweet methods from your class, should bind the providers to its SocialApiActivity first (in Sub Activity_Resume)

Does your main activity call the post and tweet methods?
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Try to disconnect the providers without publishing, connect again and then publish. This way, you will see if the disconnect causes the error.
 

Jaames

Active Member
Licensed User
Longtime User
Hi
Is it possible to access google game services with this?
Thanks
 

Douglas Farias

Expert
Licensed User
Longtime User
@Periklis Koutsogiannis
where from this error
java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1

i have this error when i use your lib but i dont know what time
 

Douglas Farias

Expert
Licensed User
Longtime User
@Periklis Koutsogiannis how can i fix this error with instagram?
only instagram i click and dont open the login screen.

this bug come 3 days ago, i have try in another device but have the same problem
 

Attachments

  • 10353638_824983074198577_5776853863173556738_n.jpg
    10353638_824983074198577_5776853863173556738_n.jpg
    26.4 KB · Views: 253

Haris Hafeez

Active Member
Licensed User
Longtime User
Hi Guys,

I've had some success with this SDK where I can post updates to Twitter. However, I am wondering if it is at all possible to send the messages in the background using a Service module?
 

Haris Hafeez

Active Member
Licensed User
Longtime User
Hi Guys,

I've had some success with this SDK where I can post updates to Twitter. However, I am wondering if it is at all possible to send the messages in the background using a Service module?
Well I've discovered it is not possible to work with this library and use it in a Service module. However, not one to give up, I've gone with using Twitter4J, which works quite well other than the fact that it requires playing with Threads.
 

Vincenzo Fabiano

Member
Licensed User
Longtime User
You can use this library to make requests with GET method in a service module? For the Facebook provider obviously..
 

Haris Hafeez

Active Member
Licensed User
Longtime User
You can use this library to make requests with GET method in a service module? For the Facebook provider obviously..
Vincenzo,
Not sure if you were asking a question here or offering me help(in which case thanks!). However, if you were asking whether you can use GET for FB integration, the answer is yes as I've just finished doing that.

I am using a combination of WebView and HttpUtils to acquire the access token that you need for posting to FB on a user's behalf. Would be glad to help if you need so :)

All the best.
 
Top