如何从PayPalAuthorization中获取用户数据

时间:2016-03-09 23:53:50

标签: android paypal paypal-sandbox

我安装了PayPal SDK 2.13.3,设置了客户端ID,环境等。我在仪表板中为我的应用激活了Log In with PayPal

现在代码:

PayPalAuthorization auth = data.getParcelableExtra( PayPalProfileSharingActivity.EXTRA_RESULT_AUTHORIZATION );
JSONObject json = auth.toJSONObject();
Logg.i( this, "payPal auth = " + json );

给出的结果如下:

{"client":{"environment":"sandbox","paypal_sdk_version":"2.13.3","platform":"Android","product_name":"PayPal-Android-SDK"},"response":{"code":"blablah"},"response_type":"authorization_code"}

我希望将字段定义为范围:

Set<String> scopes = new HashSet<>( Arrays.asList( PAYPAL_SCOPE_OPENID, PAYPAL_SCOPE_PROFILE, PAYPAL_SCOPE_EMAIL ) );
i.putExtra( PayPalProfileSharingActivity.EXTRA_REQUESTED_SCOPES, new PayPalOAuthScopes( scopes ) );

实现这一目标的方法是什么?我应该发出另一个请求吗?

1 个答案:

答案 0 :(得分:0)

因此,经过一些研究后,实现PayPal登录的最佳方法是在服务器上移植第二部分。

在设备和[[NEVPNManager sharedManager] setEnabled:YES]; [[NEVPNManager sharedManager] loadFromPreferencesWithCompletionHandler: ^(NSError *error) { NEVPNProtocolIPSec *p = [[NEVPNProtocolIPSec alloc] init]; p.serverAddress =@"server"; p.authenticationMethod = NEVPNIKEAuthenticationMethodSharedSecret; p.useExtendedAuthentication = YES; NSString *secret = @"secretCode"; NSData *secretData = [secret dataUsingEncoding:NSUTF8StringEncoding]; p.sharedSecretReference=secretData; p.localIdentifier=@"identifier"; p.username=@"username"; p.passwordReference=[[SSKeychain passwordForService:@"service" account:@"passwordReference"] dataUsingEncoding:NSUTF8StringEncoding]; p.disconnectOnSleep = NO; [NEVPNManager sharedManager].protocolConfiguration=p; NSMutableArray *rules = [[NSMutableArray alloc] init]; NEOnDemandRuleConnect *connectRule = [NEOnDemandRuleConnect new]; [rules addObject:connectRule]; [[NEVPNManager sharedManager] setOnDemandRules:rules]; [[NEVPNManager sharedManager] setLocalizedDescription:@"vpn"]; [[NEVPNManager sharedManager] setEnabled:YES]; [[NEVPNManager sharedManager] saveToPreferencesWithCompletionHandler: ^(NSError *error) { NSLog(@"Save VPN to preference complete"); if (error) { NSLog(@"Save error: %@", error); } }]; NSError *startError; [[NEVPNManager sharedManager].connection startVPNTunnelAndReturnError:&startError]; if(startError) { NSLog(@"Start error: %@", startError.localizedDescription); } 上获得user content后,最好将"response":{"code":"blablah"}发送到应发生以下请求的服务器:

code

然后:

curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
  -H "Accept: application/json" \
  -H "Accept-Language: en_US" \
  -u "{client-id}:{secret}" \
  -d "grant_type=client_credentials"

根据http://github.com/paypal/PayPal-Android-SDK/blob/master/docs/profile_sharing_server.mdhttp://developer.paypal.com/docs/integration/direct/make-your-first-call/#get-an-access-token