我想在我的macOS应用中获取PayPal帐户余额,但仍然没有找到任何解决方案。
下面是我的代码:
NSString *targetUrl = @"https://api-3t.paypal.com/nvp";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
//Make an NSDictionary that would be converted to an NSData object sent over as JSON with the request body
[request setHTTPMethod:@"POST"];
[request setURL:[NSURL URLWithString:targetUrl]];
NSString *postLength = [NSString stringWithFormat:@"application/x-www-form-urlencoded"];
[request setValue:postLength forHTTPHeaderField:@"Content-Type"];
NSString *postString = @"USER=*******************&PWD=**************&SIGNATURE= **********************&VERSION=101&METHOD=GetBalance&RETURNALLCURRENCIES=1";
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"request:%@",request.HTTPBody);
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:
^(NSData * _Nullable data,
NSURLResponse * _Nullable response,
NSError * _Nullable error) {
NSLog(@"getPaypalBalance:response:%@",[data class]);
NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"newStr:%@",newStr);
if (error) {
NSLog(@"getPaypalBalance:error:%@",error);
completionBlock(nil,error);
}else{
}
}] resume];