Hello,
My team is operating the video game Allods Online for the european market. We run three ning portal based on french, english and german languages.

 

These portals are moderated by the community itself quite successfully and we're really proud of them showing they can manage themselves quite well.

 

So recently, we also rent a webhost in php for them so that they could develop application related to their video game and since they all use Ning to login,we wanted to use the ning auth to log onto these application as well.

Again it is a volonteer who try to make the script needed to sync our three ning and the server app but he's experiencing issues and can't find why.

 

I would greatly appreciate if someone here could help us out. All the project is stuck as it rely on the ning login api we can't make run for now.


Here's what my volonteer shared to me, please have a look and feel free to ask more details :


I've got problem when I try to access to the Ning API from my webserver.This is the code I use, in order to recieve a response from the API :


<?php

$appOwnerId  = 'XXXXXXXXXXXX';

$appOwnerPwd = 'YYYYYYYYYYYY';

$apphostname = 'allodsonline-fr.ning.com';

$headers = array('Host' => $apphostname, 'Content-Type' => 'text/plain;charset=UTF-8');
$ch = curl_init();

curl_setopt($ch, CURLOPT_TIMEOUT, 10);

curl_setopt($ch, CURLOPT_URL, "http://external.ningapis.com/xn/rest/allodsonline-fr/1.0/Token?oauth_consumer_key=AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA&oauth_nonce=BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB&oauth_signature=

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC&oauth_signature_method=

PLAINTEXT&oauth_timestamp=1300353000&oauth_version=1.0");

curl_setopt($ch, CURLOPT_POST,true);

curl_setopt($ch, CURLOPT_POSTFIELDS,"");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);


//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);

curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (Compatible; Ning Auth API)");

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

 

//set HTTP Basic Auth, with the login values passed as params

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt($ch,CURLOPT_USERPWD,$appOwnerId  . ":" . $appOwnerPwd);

//
$return = curl_exec($ch);$result = json_decode($return, TRUE);print_r($result);

$error = curl_error($ch);

$errnum = curl_errno($ch);

$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

print_r("Erreur : " . $error . "<br />Numéro : " . $errnum . "<br />Code : " . $retcode);
curl_close($ch);

?>


I have got always this answer :


"Erreur : couldn't connect to host

Numéro : 7

Code : 0"


When I use the API Ning with the PHP library, it seems I have the same result.


Someone can tell me what's wrong with my code, and why not, explain me step by step how to proceed to connect my webserver to the API Ning ? I use a domain mapping :

allodsonline-fr -> guildes.fr.allods.gpotato.eu .

The problem can result from that ?


Best regards.

Views: 96

Reply to This

Replies to This Discussion

Two suggestions:

 

1. The /Token endpoint requires you to use HTTPS, your code is using plain HTTP

2. Send the OAuth parameters as POST data by using the CURLOPT_POSTFIELDS setting

Hello, 

I modified the code with the recommendations which you gave me, but nothing changes; I always obtain the error described previously.

This is my code : 

<?php

$appOwnerId  = 'allods-guildportal@gpotato.eu';

$appOwnerPwd = '**************';

$apphostname = 'allodsonline-fr.ning.com';

$headers = array('Host' => $apphostname, 'Content-Type' => 'text/plain;charset=UTF-8');
$ch = curl_init();

curl_setopt($ch, CURLOPT_TIMEOUT, 10);

curl_setopt($ch, CURLOPT_URL, "https://external.ningapis.com/xn/rest/allodsonline-fr/1.0/Token");

curl_setopt($ch, CURLOPT_POST,true);

curl_setopt($ch, CURLOPT_POSTFIELDS,"oauth_consumer_key=0126284b-ce17-466a-a403-dba1d73955cb&oauth_nonce=c2c36513cd6bf0bec2a7e99e3d2f674e&oauth_signature=51KRmK8jBQiX4Y%2FpX4Ekg1DuOmg%3D&oauth_signature_method=PLAINTEXT&oauth_timestamp=1300353000&oauth_version=1.0");curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

 

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (Compatible; Ning Auth API)");

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

//set HTTP Basic Auth, with the login values passed as params

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt($ch,CURLOPT_USERPWD,$appOwnerId  . ":" . $appOwnerPwd);

//
$return = curl_exec($ch);

$result = json_decode($return, TRUE);

print_r($result);

//

$error = curl_error($ch);

$errnum = curl_errno($ch);

$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

print_r("Erreur : " . $error . "<br />Numéro : " . $errnum . "<br />Code : " . $retcode);

//
curl_close($ch);

?>

 

Thanks for your advices

Try again without explicitly setting the 'Host' header, that part isn't necessary.

Reply to Discussion

RSS

Blog Posts

Getting Started

Posted by Kyle Ford on October 13, 2010 at 8:00am 3 Comments

A Note on API Pricing

Posted by Phil McCluskey on October 1, 2010 at 8:55am 0 Comments

Welcome to Build!

Posted by Kyle Ford on September 30, 2010 at 8:30pm 1 Comment

Ning Status

© 2024   Created by Build Team.   Powered by

Badges  |  Report an Issue  |  Terms of Service