Search code examples
phpjavascriptapigigya

Gigya User Object is Missing


I've just started using Gigya to allow users to connect to my site. I already have a login system so I just want to connect existing users to the Gigya service.

To do this I have called the "gigya.services.socialize.notifyLogin" function which returns a Gigya User object with the UID provided by my site. [fig 1] Do I need to do anything with this User object, like add it to a cookie or is it just for reference.

The problem that Im having is on another page, I want to allow users to connect to their social media accounts. I use the "showAddConnectionsUI" function passing my api key, but the returned object does NOT have the User object in, although the documentation says it should. How do I get the users conenctions and the key information from this function. Do I need to send any additional information along with my api key. [fig 2]

I have spent several days reading the wiki, documentation and forum for advice but I am still stuck. Any help would be greatly appreciated. Thanks in advance, Ben

[fig 1]

<script type="text/javascript" src="http://cdn.gigya.com/js/socialize.js?apiKey=<?php echo $key; ?>"></script>
<script type="text/javascript">
    var gigyaConf = { APIKey: "<?php echo $key; ?>", signIDs: "true" }

    var signature = "<?php echo $signature; ?>";
    var siteUID   = "<?php echo $userId; ?>";
    var timestamp = "<?php echo $timestamp; ?>";

    var gigyaParams =
    {
        siteUID:siteUID,
        timestamp:timestamp,
        signature:signature,
        callback:gigyaNotifyLoginCallback
    };

    gigya.services.socialize.notifyLogin(gigyaConf, gigyaParams);

    function gigyaNotifyLoginCallback(eventObj) {
        if ( eventObj.errorCode != 0 ) {
            alert('Gigya Error: ' + eventObj.errorMessage);
        }
    }
</script>

[fig 2]

<script type="text/javascript" lang="javascript" src="http://cdn.gigya.com/JS/socialize.js?apikey=<?php echo $key; ?>"></script>
<script>
    var conf = { APIKey: '<?php echo $key; ?>', signIDs: 'true' };

    $(document).ready(function(){
        gigya.services.socialize.getUserInfo(conf, { callback: renderUI });

        gigya.services.socialize.addEventHandlers(conf,
        {
            onConnectionAdded: renderUI,
            onConnectionRemoved: renderUI
        });
    });
</script>

<script>
    function renderUI(res) {
        if (res.user != null && res.user.isConnected) {
            document.getElementById("name").innerHTML = res.user.nickname;
            if (res.user.thumbnailURL.length > 0)
                document.getElementById("photo").src = res.user.thumbnailURL;
            else
                document.getElementById("photo").src = "http://cdn.gigya.com/site/images/bsAPI/Placeholder.gif";
            document.getElementById("profile").style.display = "block";
        } else {
            document.getElementById("profile").style.display = "none";
        }
    }
</script>
<div id="content">
    <h5>Step 1: Connect</h5>
    <div id="divConnect"></div>
    <script type="text/javascript">
        gigya.services.socialize.showAddConnectionsUI(conf, {
            height:65,
            width:175,
            showTermsLink:false,
            hideGigyaLink:true,
            useHTML:true,
            containerID: "divConnect"
        });
    </script>
    <br />
    <h5>Step 2: See User Info</h5><br />
    <div id=profile style="display:none;">
        <img id="photo" src="" width="60" />
        <br />
        <span id="name" ></span>
    </div>
</div>

Any help, advice, code snippits that would help will be greatly appreciated


Solution

  • Re: your first question, not required to do anything special with the Gigya User object. It's for your reference.

    Re: your code, I can't tell if you're using JQuery but I was getting an error with your $(document).ready function. I modified your code slightly by adding body onLoad and everything worked. This assumes you have connected with a provider. Here's my code... hope it helps:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript" lang="javascript" src="http://cdn.gigya.com/JS/socialize.js?apikey=<?php echo $key; ?>"></script>
    <script>
    
        var conf = { APIKey: '<?php echo $key; ?>', signIDs: 'true' };
    
        function onLoad() {
    
            gigya.services.socialize.getUserInfo(conf, { callback: renderUI });
    
            gigya.services.socialize.addEventHandlers(conf,
            {
                onConnectionAdded: renderUI,
                onConnectionRemoved: renderUI
            });
        }
    
    </script>
    
    <script>
        function renderUI(res) {
    
            if (res.user != null && res.user.isConnected) {
                document.getElementById("name").innerHTML = res.user.nickname;
                if (res.user.thumbnailURL.length > 0)
                    document.getElementById("photo").src = res.user.thumbnailURL;
                else
                    document.getElementById("photo").src = "http://cdn.gigya.com/site/images/bsAPI/Placeholder.gif";
                document.getElementById("profile").style.display = "block";
            } else {
                document.getElementById("profile").style.display = "none";
            }
        }
    </script>
    
    
    <body onload="onLoad()">
    
    <div id="content">
        <h5>Step 1: Connect</h5>
        <div id="divConnect"></div>
        <script type="text/javascript">
            gigya.services.socialize.showAddConnectionsUI(conf, {
                height:65,
                width:175,
                showTermsLink:false,
                hideGigyaLink:true,
                useHTML:true,
                containerID: "divConnect"
            });
        </script>
        <br />
        <h5>Step 2: See User Info</h5><br />
        <div id=profile style="display:none;">
            <img id="photo" src="" width="60" />
            <br />
            <span id="name" ></span>
        </div>
    </div>
    
    </body>
    </html>