I know this question is already asked and answered but that didn't help me. I am working on integration of few social apps like Facebook and Twitter by using social auth lib. I have successfully implemented them by following code:
public class SignUp extends Activity implements OnClickListener {
private EditText email_mEditText,password_mEditText;
SocialAuthAdapter socialAuthAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_up);
socialAuthAdapter = new SocialAuthAdapter(new ResponseListener());
socialAuthAdapter.authorize(SignUp.this, Provider.FACEBOOK);
socialAuthAdapter.signOut(this, Provider.FACEBOOK.toString());
With this code I am able to open Facebook to authorize but I want to get the access token. I tried the following code to get the access token in my activity:
socialAuthAdapter.getCurrentProvider().getAccessGrant().getKey();
However, this crashes the app and shows a NullPointerException
.
03-12 16:14:37.278: E/AndroidRuntime(19405): FATAL EXCEPTION: main
03-12 16:14:37.278: E/AndroidRuntime(19405): Process: com.technearby.app.main, PID: 19405
03-12 16:14:37.278: E/AndroidRuntime(19405): java.lang.NullPointerException
03-12 16:14:37.278: E/AndroidRuntime(19405): at com.technearby.app.main.SignUp.onClick(SignUp.java:107)
03-12 16:14:37.278: E/AndroidRuntime(19405): at android.view.View.performClick(View.java:4438)
03-12 16:14:37.278: E/AndroidRuntime(19405): at android.view.View$PerformClick.run(View.java:18422)
03-12 16:14:37.278: E/AndroidRuntime(19405): at android.os.Handler.handleCallback(Handler.java:733)
03-12 16:14:37.278: E/AndroidRuntime(19405): at android.os.Handler.dispatchMessage(Handler.java:95)
03-12 16:14:37.278: E/AndroidRuntime(19405): at android.os.Looper.loop(Looper.java:136)
03-12 16:14:37.278: E/AndroidRuntime(19405): at android.app.ActivityThread.main(ActivityThread.java:5001)
03-12 16:14:37.278: E/AndroidRuntime(19405): at java.lang.reflect.Method.invokeNative(Native Method)
03-12 16:14:37.278: E/AndroidRuntime(19405): at java.lang.reflect.Method.invoke(Method.java:515)
03-12 16:14:37.278: E/AndroidRuntime(19405): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
03-12 16:14:37.278: E/AndroidRuntime(19405): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
03-12 16:14:37.278: E/AndroidRuntime(19405): at dalvik.system.NativeStart.main(Native Method)
You have to add providers yourself to the adapter. For example, adapter.addProvider(Provider.FACEBOOK, R.drawable.facebook);
.