Tuesday, 30 September 2014

The evil "QWZV...==" in PayPal Oauth2.0 for user profile sharing

OK, so today I was ready to fetch some user profile information from PayPal account and I bump into a problem, PayPal is using OAuth2.0 to grant user access token which can be used to fetch all relevant informations that has been exposed by the PayPal application that you connected with.

When I was reading the PayPal official guide, I saw this.

OK, here are the 2 sections that has been highlighted.
1. the production link
It took me quite while to figure out that this is actually the production link that I'm testing with! The correct link should come from sandbox which is

https://api.sandbox.paypal.com/v1/oauth2/token

The guide should have indicated it, right? LOL.

2. The evil QWZV...==
the funny thing is the document never tells you where does this value come from. After a bit research, this is actually Basic Http Authentication headers and according to this https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/#get-an-access-token, this value should be generated by combining client_id and secret with ":" separated by.

        String s = BASE64Encoder.encode("yout_client_id:your_client_secret".getBytes());

Here is how you get that value in Java FYI.

We are finally good to go to get the access token.




I hope this solves your problem with getting access token from PayPal, happy integration with PayPal, :)

Thursday, 25 September 2014

Safely delete fragment in viewpager

People tend to have multiple fragments when using viewpager, here is a good way to get rid of those fragments after you exit the current screen that has the viewpager.

in your onDestroy method:



  
  for (int i = 0; i < pagerCount; i++) {
       FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
       MyFragment f = (MyFragment) getSupportFragmentManager().findFragmentByTag(getFragmentTag(i));
       trans.remove(f).commitAllowingStateLoss();

  }
private String getFragmentTag(int position) {
        return "android:switcher:" + R.id.your_view_pageer_id + ":" + position;
    }
Hope this helps :)