Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE
My Carrier: Telcel

I can't find a way to make XML-RPC calls through a QT library - Tapatalk Forums App

[ Edited ]

Hello everybody!

 

I'm making a forums app, and I was working with JSON to retrieve all data related with Wordpress(I made it successfully), so now when I tried to retrieve all related forums information (vBulletin) just it is not working Smiley Sad , after that I was trying to use a Tapatalk api, (it's correctly installed inside the forum) but I was looking for samples or related info without succes..

 

I was trying with vBulletin api (REST calls method) :

 

http://www.vbulletin.com/vbcms/content.php/334-mobile-api

 

But only 'Api_init' call works fine, another calls can't be invoked successfully.

 

So I'm trying with tapatalk API (it works under XML-RPC calls):

 

http://tapatalk.com/api/api_home.php

 

¿Can you help me to find any way to retrieve the data for our forum? Smiley Sad

 

Forum url: www.blackberryempire.com/forum

 

Thanks!

BlackBerry Development Advisor
Posts: 143
Registered: ‎03-08-2012
My Device: Z10
My Carrier: Bell

Re: I can't find a way to make XML-RPC calls through a QT library - Tapatalk Forums App

I think you will have an easier time getting the RESTful API working via QNetworkAccessManager.  Can you provide more information with respect to the next RESTful API you tried to implement and what data you received back when you tried to call it? 

Developer
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE
My Carrier: Telcel

Re: I can't find a way to make XML-RPC calls through a QT library - Tapatalk Forums App

[ Edited ]

I'll explan all in the following message:

Developer
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE
My Carrier: Telcel

Re: I can't find a way to make XML-RPC calls through a QT library - Tapatalk Forums App

It must be simple, here is an example about how can I check if the api is working with a wordpress reference:

 

http://blackberryempire.com/verizon-wireless-pushing-blackberry-os-10.2.1/?json=1

 

There you can see all json working fine.

 

Then, going to the vbulletin api:

 

http://blackberryempire.com/forum/api.php?api_m=api_init&clientname=bbeapp&clientversion=0.1&platfor...

 

It returns:

 

{"apiversion":510,"apiaccesstoken":"041f60304c14084b7a48f721ea5a47eb","bbtitle":"BlackBerry Forums at BlackBerryEmpire.com","bburl":"http:\/\/blackberryempire.com\/forum\/core","bbactive":1,"forumhome":"http:\/\/blackberryempire.com\/forum\/forum","vbulletinversion":"5.1.0 Beta 1","contenttypes":{"Album":"8","Announcement":"4","Attach":"34","Calendar":"14","Channel":"29","Event":"13","Forum":"3","Gallery":"32","Infraction":"16","Link":"36","Photo":"33","Picture":"9","PictureComment":"10","Poll":"31","Post":"1","PrivateMessage":"15","Redirect":"38","Report":"37","Signature":"17","SocialGroup":"7","SocialGroupDiscussion":"6","SocialGroupMessage":"5","Text":"30","Thread":"2","User":"12","UserNote":"18","Video":"35","VisitorMessage":"11"},"features":{"blogenabled":1,"cmsenabled":0,"pmsenabled":1,"searchesenabled":1,"groupsenabled":1,"albumsenabled":0,"multitypesearch":1,"visitor_messagingenabled":1,"taggingenabled":1,"visitor_trackingenabled":0,"paidsubs":0,"friendsenabled":0,"activitystream":1},"permissions":[],"show":{"registerbutton":1},"apiclientid":12,"secret":"yY5hQKLjHUZPDrKtgpWyKsywfqumaEVP"}

 all needed info to invoke api, following the documentation I made the following data:

 

URL request:
 
 
access token: 041f60304c14084b7a48f721ea5a47eb
vb_login_password: xxxxxxxx
vb_login_username: santito95
apiclientid: 12
secret: yY5hQKLjHUZPDrKtgpWyKsywfqumaEVP
CPanel apikey: NBVkLWT1
 
signstr: vb_login_username=santito95&api_m=login_login&vb_login_password=xxxxxxxx
 
MD5 encryption:
vb_login_username=santito95&api_m=login_login&vb_login_password=xxxxxxxxx
041f60304c14084b7a48f721ea5a47eb12yY5hQKLjHUZPDrKtgpWyKsywfqumaEVPNBVkLWT1
 
MD5 Result:
 76c788e0f03ba41b929310b1a759748d
 
 
But it's not working, not shows any error Smiley Sad
 
 
BlackBerry Development Advisor
Posts: 143
Registered: ‎03-08-2012
My Device: Z10
My Carrier: Bell

Re: I can't find a way to make XML-RPC calls through a QT library - Tapatalk Forums App

Are you sure you are supposed to pass the data in the URL?  That only works if the API is a GET API and if it doesn't expect the data as a form-encoded data, POST data or JSON (which would be passed as MIME data usually).  Do you have documentation for the API that you can check with respect to how it expects to receive the data?

Developer
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE
My Carrier: Telcel

Re: I can't find a way to make XML-RPC calls through a QT library - Tapatalk Forums App

Sure you can check here:

 

http://www.vbulletin.com/vbcms/content.php/334-mobile-api

 

In the api.php documentation you can see the following info:

 

api.php


This is a central entry script for all clients to call. It handles clients' GET, POST requests and HTTP headers (For authentication / requests validation etc.). It also takes charge of translating method name to URL and do the actual requesting to the URL.

Method name is required for api.php either by GET or POST. Also most of the methods require sessionhash and signature.

So here's an example of the request URL:

http://www.yourforumurl.com/api.php?api_m=forum_markread&api_c=clientid&api_s=accesstoken&api_sig=si...

From the example, you'll see:

  1. api.php specific params are prefixed with 'api_'
  2. api_m = method name
  3. api_c = ClientID.
  4. api_s = Access token.
  5. api_sig = signature of the request
  6. api_v = the api version called by the request
  7. b=value1&a=value2 are the HTTP GET params accepted by the method (forum_markread) of the API
BlackBerry Development Advisor
Posts: 143
Registered: ‎03-08-2012
My Device: Z10
My Carrier: Bell

Re: I can't find a way to make XML-RPC calls through a QT library - Tapatalk Forums App

This section explains what you are doing wrong:

 

Request/Result Verification
Each API request (except api_init) should be signed to make sure the requests in a session are made by one same client. Also the results returned by the server should be signed to make sure they were returned from the same vB instance.

How to sign a request (in PHP):

PHP Code:
// The HTTP GET params for an API method (without api related params except api_m. see below)
$requestparams = array('api_m' => 'forumdisplay''b' => 'value1''a' => 'value2'); 

// Sort GET params by key
ksort($requestparams); 

// $signstr = 'a=value2&api_m=forumdisplay&b=value1';
$signstr http_build_query($requestparams'''&'); 

// The signature is the md5 value of $signstr + accesstoken + clientid + secret + API key
$sign md5($signstr $apiaccesstoken $apiclientid $secret $apikey); 

How to verify a result (in PHP):

PHP Code:
// The sign value returned by the server (Authorization header);
$sign $_SERVER['HTTP_AUTHORIZATION']; 

$data 'the raw xml data returned by the server';

// The correct signature is the md5 value of $data + accesstoken + clientid + secret (all can be fetched from api_init)
$signtoverify md5($data.$apiaccesstoken.$apiclientid.$secret); 

if (
$sign != $signtoverify) {
  
// Throw error msg here

The server will return the data with a signature in the HTTP header. The client should verify each result returned by the server with the signature.

 

 

According to the above, you have to generate a MD5 hash from five different pieces of information including the signstr.  I could misreading what you sent me but I don't think you included everything you needed to.  I think fixing that will probably fix the API call you were trying.  According to the above, you also need to verify the results to be sure it is coming back from the same server instance.

 

Let me know if that change helps.

Developer
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE
My Carrier: Telcel

Re: I can't find a way to make XML-RPC calls through a QT library - Tapatalk Forums App

Anyway it should give any error message, I was using the following code in php, but doesn't work too..

 

request_auth.php

 

<?php


$forumUrl = 'http://www.blackberryempire.com/forum/';
$apikey = 'NBVkLWT1';

//Parameters 
$clientname = "blackberryclient"; 
$clientversion ="0.1"; 
$platformname = "blackberry10"; 
$platformversion ="2.5"; 
$uniqueid = "1234"; 
$apiurl= $forumUrl .'api.php';


error_reporting(E_ALL); 

///////////////////////////////////////// ACTION 

if(isset($_POST['username']) && isset($_POST['password'])) { 
$userName = $_POST['username']; 
$password = $_POST['password']; 

if($userName != '' && $password != '') { 
$jsarray = initApiRequest($clientname, $clientversion, $platformname, $platformversion, $uniqueid, $apiurl);
$jsarray = doAuthenticate($jsarray, $userName, $password, $apikey, $apiurl);

echo "<hr>";
if($jsarray->{'response'}->{'errormessage'}[0] == "redirect_login") {
echo 'login success! ('. $jsarray->{"session"}->{'userid'} .') '. $jsarray->{'response'}->{'errormessage'}[1];

} else {
echo "login failed!";
}
echo "<hr>";
} else { 
echo "userName == '' || password == ''"; 
} 
} 
///////////////////////////////////////// FUNCTIONS 

function initApiRequest($clientname, $clientversion, $platformname, $platformversion, $uniqueid, $apiurl) {
$init_request = $apiurl .'?api_m=api_init&clientname='. $clientname .'&clientversion='.$clientversion .'&platformname='.$platformname .'&platformversion=' .$platformversion .'&uniqueid='.$uniqueid; 
$jsarray = doRestRequest($init_request); 
return $jsarray; 
} 

function doAuthenticate($jsarray, $userName, $password, $apikey, $apiurl) {
$password = md5($password); 
$requestparams = array('api_m' => 'login_login', 'vb_login_username' => $userName, 'vb_login_md5password' => $password, 'cookieuser' => 1);

$api_sig = buildApiSig($jsarray, $apikey, $requestparams);
$api_registration_information = buildApiRegistrationString($jsarray, $api_sig);
$login_request = buildRequestString($requestparams, $api_registration_information);

$url = $apiurl .'?api_m=login_login';
$jsarray = doRestRequestUrlencoded($login_request, $url); 
return $jsarray; 
}

function buildApiSig($jsarray, $apikey, $requestparams) {
ksort($requestparams); 

$login_string = http_build_query($requestparams, '', '&'); 

$apiaccesstoken = urlencode($jsarray->{'apiaccesstoken'}); 
$apiclientid = urlencode($jsarray->{'apiclientid'}); 
$secret = urlencode($jsarray->{'secret'}); 

$api_sig = urlencode(md5($login_string . $apiaccesstoken . $apiclientid . $secret . $apikey));
return $api_sig;
}

function buildApiRegistrationString($jsarray, $api_sig) {
$apiaccesstoken = urlencode($jsarray->{'apiaccesstoken'}); 
$apiclientid = urlencode($jsarray->{'apiclientid'}); 
$apiversion = urlencode($jsarray->{'apiversion'}); 

$api_registration_information = 'api_c='. $apiclientid .'&api_s='. $apiaccesstoken .'&api_sig='. $api_sig .'&api_v='. $apiversion;
return $api_registration_information;
}

function buildRequestString($requestparams, $api_registration_information) {
unset($requestparams['api_m']);
echo "<hr>". http_build_query($requestparams, '', '&') ."<hr>";
$login_request = '&'. $api_registration_information .'&'. http_build_query($requestparams, '', '&');
return $login_request;
}

function doRestRequest($restRequest) { 
echo "<br>DO REST REQUEST[". $restRequest ."]<br>"; 

$content = ''; 
//Open and read the content 
$fp = fopen($restRequest, 'r'); 

// keep reading until there's nothing left 
while ($line = fread($fp, 1024)) { 
$content .= $line; 
} 
fclose($fp); 


echo "<hr>"; 
var_dump(json_decode($content, true)); 
echo "<hr>"; 

//decode the content 
$jsarray = json_decode($content); 
return $jsarray; 
} 

function doRestRequestUrlencoded($restRequest, $url) { 
echo "<br>DO REST REQUEST[". $restRequest ."]<br>"; 
$context_options = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded",
'content' => $restRequest
)
);
$context = stream_context_create($context_options);

$content = ''; 
//Open and read the content 
$fp = fopen($url.$restRequest, 'r', false, $context); 

// keep reading until there's nothing left 
while ($line = fread($fp, 1024)) { 
$content .= $line; 
} 
fclose($fp); 

echo "<hr>"; 
var_dump(json_decode($content, true)); 
echo "<hr>"; 

//decode the content 
$jsarray = json_decode($content); 
return $jsarray; 
} 

function doRestRequestUrlencodedPOST($restRequest, $url) { 
echo "<br>DO REST REQUEST[". $restRequest ."]<br>"; 
$context_options = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded",
'content' => $restRequest
)
);
$context = stream_context_create($context_options);

$content = ''; 
//Open and read the content 
$fp = fopen($url.$restRequest, 'r', false, $context); 

// keep reading until there's nothing left 
while ($line = fread($fp, 1024)) { 
$content .= $line; 
} 
fclose($fp); 

echo "<hr>"; 
var_dump(json_decode($content, true)); 
echo "<hr>"; 

//decode the content 
$jsarray = json_decode($content); 
return $jsarray; 
} 
?> 

 Index.html:

 

<html> 
<head> 
</head> 
<body> 
<form action="request_auth.php" method="post"> 
<p>Username: <input type="text" name="username" /></p> 
<p>Password: <input type="password" name="password" /></p> 
<p><input type="submit" /></p> 
</form> 
</body> 
</html>

It shows an error: 

 

failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\request_auth.php on line 126

 

Smiley Sad I need find a way, I tried a generic app (under android) and it can access to the forum successfully using vBulletin Mobile api.

 

BlackBerry Development Advisor
Posts: 143
Registered: ‎03-08-2012
My Device: Z10
My Carrier: Bell

Re: I can't find a way to make XML-RPC calls through a QT library - Tapatalk Forums App

In your PHP code, you are URL-encoding the accesstoken, clientid and secret.  The documentation sample script does not do that.  I suspect that is causing problems in your PHP code.

Developer
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE
My Carrier: Telcel

Re: I can't find a way to make XML-RPC calls through a QT library - Tapatalk Forums App

are you talking about buildApiSig() function?, I removed it but doesn't work still

 

function buildApiSig($jsarray, $apikey, $requestparams) {
ksort($requestparams); 

$login_string = http_build_query($requestparams, '', '&'); 

$apiaccesstoken = ($jsarray->{'apiaccesstoken'}); 
$apiclientid = ($jsarray->{'apiclientid'}); 
$secret = ($jsarray->{'secret'}); 

$api_sig = urlencode(md5($login_string . $apiaccesstoken . $apiclientid . $secret . $apikey));
return $api_sig;
}

 But it returns the same error:

 

Warning: fopen(http://www.blackberryempire.com/forum/api.php?api_m=login_login&api_c=18&api_s=646de90a0597dda59ad24...

 

failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\request_auth.php on line 126