Getting logged in members Display Name or Email address via PHP API

Hi,

I have managed to get the current logged in members email address, but think I have made it overly complicated. This is what I have done, my question is, is there a more efficient way to do it?

 

In my ning network, I have added a text box and inside this, put the following HTML:

<iframe id="testIframe" horizontalscrolling="no" allowtransparency="allowtransparency" style="border: none; width: 500px; overflow-x: hidden;" name="testIframe" frameborder="0"></iframe>


<script language="JavaScript" type="text/javascript">// <![CDATA[
    var author = ning.CurrentProfile.id;
    document.getElementById("testIframe").src = "http://xxx.com/test.php?author="+author;
// ]]></script>

 

Now in the file test.php I have:

 

<?php
require_once('ning-api-php/NingApi.php');

//Get HTTP vars
$author = trim($_GET['author']);

$args = array(
    "author" => $author
);

$result = NingApi::instance()->user->fetch($args );

print_r($result);
?>

 

This then gives me access to the logged in members email address, which I will then use to pull out of SalesForce some relevant data for that member and display it.

It works, but can I do this better?

Views: 566

Reply to This

Replies to This Discussion

You can access the member's full name via 'ning.CurrentProfile.fullName'. You can't access email addresses via JavaScript, so your current method is the best option for now.

Why does this work fine on my test network, but doesn't work for non-admin users (i.e. members) on my live network?

 

On my live network, I get the following error:

Fatal error: Uncaught No User matches your query. (404) 3-1 thrown in /var/www/app.royalcanin.ca/ning/api/ning-api-php/NingException.php on line 56

 

In the above code example, if the $author is a 'member' id, I get the above error.

Works fine for admin. On test, members and admins get data returned appropriately.


Ok, ignore me.

 

I hadn't updated my tokens and network address in NingApi.php

 

It was still set to my test network. Schoolboy error. Nothing to see here...move along. All working fine!

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

All systems Go!

All Ning Networks are fully operational and speedy. Things are humming along nicely.

© 2017   Created by Build Team.   Powered by

Badges  |  Report an Issue  |  Terms of Service