the page returns as xml, and this xml will be process in the C++ code. This code is copied from others, edited accordingly to do what I need. so credits not for me =)
echo '';
}
echo '';
} else {
if ($retcode == 400) {
//wrong selector (not id or email) -- ignored
//echo "wrong selector!";
} else if ($retcode == 401) {
//invalid login or password so display this ugly page with a link back to the blog entry
// echo "invalid login or pw";
} else {
//unknown error
// echo "unknown error!";
//print_r($result);
}
}
curl_close($curl);
I'm not really sure I know what you want to create. But I'll post some codes that i use to communicate with ning. I don't really use ning anymore though. And as I said in that thread, I still have some problem authenticating, but I can bypass that problem doing some other way, not really 'safe', because then anyone can access the php page as long as they know the page name, but at least it works.
// some other url that you can try using
//string signInUrl = "https://" + apphostname + "/xn/rest/2.0/profile(email='" + appOwnerId + "')/signin?max-age=0";
//string url = "https://" + apphostname + "/xn/atom/1.0/content(type='User')";
// a php file that I wrote to do the authentication and return the user list
string url = "http://mysite.ning.com/GetUser.php";
// this is the write function used above
static int writer(char *data, size_t size, size_t nmemb,
std::string *writerData)
{
if (writerData == NULL)
return 0;
writerData->append(data, size*nmemb);
return (int) (size * nmemb);
}
so yes, I think you can use this to get your messages, friends list, activities etc, as long as you know how to access them from the ning database via php. Basically it's just a program that calls a php page, it doesn't do much. Nothing complicated. Hope it helps =)
Comment Wall (3 comments)
You need to be a member of Ning Developer Docs to add comments!
Join Ning Developer Docs
$appOwnerId = 'myid@myemail.com';
$appOwnerPwd = 'mypassword';
$apphostname = 'mysite.ning.com';
//first we call the signIn endpoint, to verify that user/password is
//correct.
$url = 'https://' . $apphostname . '/xn/rest/2.0/profile(email=\'' . $appOwnerId . '\')/signin?max-age=0';
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
//set a user agent that can be differentiation
curl_setopt($curl,CURLOPT_USERAGENT,"Mozilla/4.0 (Compatible; Ning Auth API)");
$headers = array('Host' => $apphostname, 'Content-Type' => 'text/plain;charset=UTF-8');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//set HTTP Basic Auth, with the login values passed as params
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
if(!empty($appOwnerId) && !empty($appOwnerPwd)) {
curl_setopt($curl,CURLOPT_USERPWD,$appOwnerId . ":" . $appOwnerPwd);
}
$result = curl_exec($curl);
$error = curl_error($curl);
$retcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($retcode == 204) {
// fetch user data
$url = "https://" . $apphostname . "/xn/atom/1.0/content(type='User')";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_USERPWD, $appOwnerId.':'.$appOwnerPwd);
$result = curl_exec($curl);
$retcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$xml = new SimpleXMLElement($result);
header("Content-type: text/xml");
echo chr(60).chr(63).'xml version="1.0" encoding="utf-8" '.chr(63).chr(62);
echo '';
foreach($xml->entry as $entry) {
//print_r($entry);
$screenName = $entry->title;
//echo $first . " " . $second . " " . $third . " " . $total . " " . $name . " ";
$q =XN_Query::create('Content')
->filter( 'type', 'eic', 'MyOwnUserData')
->filter('my->UserID', 'eic', $screenName)
->execute();
echo '';
echo '' . $screenName . '';
$profile = XN_Profile::load($screenName);
echo '' . $profile->fullName . '';
echo '' . $q[0]->my->FirstPlace . '';
echo '' . $q[0]->my->SecondPlace . '';
echo '' . $q[0]->my->ThirdPlace . '';
$lost = $q[0]->my->TotalRace - $q[0]->my->FirstPlace - $q[0]->my->SecondPlace - $q[0]->my->ThirdPlace;
echo '' . $lost . '';
echo '';
}
echo '';
} else {
if ($retcode == 400) {
//wrong selector (not id or email) -- ignored
//echo "wrong selector!";
} else if ($retcode == 401) {
//invalid login or password so display this ugly page with a link back to the blog entry
// echo "invalid login or pw";
} else {
//unknown error
// echo "unknown error!";
//print_r($result);
}
}
curl_close($curl);
Here:
string GetUser(CURL *curl)
{
CURLcode res;
string appOwnerId = "myid@myemail.com";
string appOwnerPwd = "mypassword";
string apphostname = "mysite.ning.com";
string appIdPwd = appOwnerId + ":" + appOwnerPwd;
string buffer;
// some other url that you can try using
//string signInUrl = "https://" + apphostname + "/xn/rest/2.0/profile(email='" + appOwnerId + "')/signin?max-age=0";
//string url = "https://" + apphostname + "/xn/atom/1.0/content(type='User')";
// a php file that I wrote to do the authentication and return the user list
string url = "http://mysite.ning.com/GetUser.php";
// initialization
CURL* curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
//printf("We received: %s\n", buffer.c_str());
}
curl_easy_cleanup(curl);
return buffer; // output from the link
}
// this is the write function used above
static int writer(char *data, size_t size, size_t nmemb,
std::string *writerData)
{
if (writerData == NULL)
return 0;
writerData->append(data, size*nmemb);
return (int) (size * nmemb);
}
so yes, I think you can use this to get your messages, friends list, activities etc, as long as you know how to access them from the ning database via php. Basically it's just a program that calls a php page, it doesn't do much. Nothing complicated. Hope it helps =)