4

I am able to get the email when the user sign in via apps.com.

My problem is I cant get first name and last name. here's a sample code from intuit, I tried adding 'namePerson/first' and 'namePerson/last', to the required attribute but it doesn't help.

The codes that i use is from intuit example https://github.com/IntuitDeveloper/SampleApp-PHP-for-OpenId-OAuth-V3APICalls/blob/master/PHPSample/index.php

<?php
  ob_start();
  require_once("config.php");
  require_once("CSS Styles/StyleElements.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<h3>IPP PHP Sample App</h3>
<title>IPP PHP sample</title>
<script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script>
<script>
    // Runnable uses dynamic URLs so we need to detect our current //
    // URL to set the grantUrl value   ########################### //
    /*######*/ var parser = document.createElement('a');/*#########*/
    /*######*/parser.href = document.url;/*########################*/
    // end runnable specific code snipit ##########################//
    intuit.ipp.anywhere.setup({
        menuProxy: '',
        grantUrl: 'http://'+parser.hostname+'/sampleqboapp/PHPSample/oauth.php?start=t' 
        // outside runnable you can point directly to the oauth.php page
    });
  </script>


</head>
<body>

<?php
    # This sample uses the LightOpenID library located here:  https://gitorious.org/lightopenid
    echo '<div> Please refer to the <a target="_blank" href="http://localhost/PHPSample/ReadMe.htm">Read Me</a> page for detailed instructions and information regarding this sample </div><br />';

    require 'lightopenid-lightopenid/openid.php';
    try {
        # Change 'localhost' to your domain name.
        $openid = new LightOpenID('localhost');
        if(!$openid->mode) {
            echo '<div> This sample uses PHP 5.6.3 and Intuit PHP SDK version v3-php-sdk-2.2.0-RC
            </div><br />';

            echo '<div> To be listed on QuickBooks Apps.com, any app must implement OpenID for user authentication. This sample uses LightOpenID library located at
            <a target="_blank" href="https://gitorious.org/lightopenid"> https://gitorious.org/lightopenid </a><br />
            </div><br />';

            # The connectWithIntuitOpenId parameter is passed when the user clicks the login button below
            # The subscribeFromAppsDotCom parameter is an argument in the OpenID URL of a sample app on developer.intuit.com
            # Example of OpenID URL:  http://localhost/ippPhpOpenId/IPP-PHP-OpenID-Login.php?subscribeFromAppsDotCom


            $openid->identity = "https://openid.intuit.com/Identity-jameshwart";
                # The following two lines request email and full name
                # from the Intuit OpenID provider


                $openid->required = array(
                    'namePerson/friendly', 
                    'contact/email' , 
                    'contact/country/home',
                    'namePerson', 
                    'namePerson/first', 
                    'namePerson/last',
                    'pref/language', 
                ); 

                header('Location: ' . $openid->authUrl());

        } elseif($openid->mode == 'cancel') {
            echo 'User has canceled authentication!';
        } else {
            # Print the OpenID attributes that we requested above, email and full name
            echo '<pre>';
            print_r($openid);
            print_r($openid->getAttributes());
            echo '</pre>';
            # Add a link to allow the user to logout. The link makes a JavaScript call to intuit.ipp.anywhere.logout()
            echo '<br /><a href="javascript:void(0)" onclick="return intuit.ipp.anywhere.logout(function () { window.location.href = \'http://localhost/sampleqboapp/PHPSample/index.php\'; });">Sign Out</a>';

            //oAuth code

                    require_once('../v3-php-sdk-2.2.0-RC/config.php');  // Default V3 PHP SDK (v2.0.1) from IPP
                    require_once(PATH_SDK_ROOT . 'Core/ServiceContext.php');
                    require_once(PATH_SDK_ROOT . 'DataService/DataService.php');
                    require_once(PATH_SDK_ROOT . 'PlatformService/PlatformService.php');
                    require_once(PATH_SDK_ROOT . 'Utility/Configuration/ConfigurationManager.php');
                    error_reporting(E_ERROR | E_PARSE);



                    // After the oauth process the oauth token and secret 
                    // are storred in session variables.
                    $tk = $_SESSION['token'];
                    if(!isset($_SESSION['token'])){
                      echo "<h3>You are not currently authenticated!</h3>";
                      echo '<div> This sample uses the Pecl Oauth library for OAuth. </div> <br />
                            <div> If not done already, please download the Oauth package from
                            <a target="_blank" href="http://pecl.php.net/package/oauth"> http://pecl.php.net/package/oauth </a> and follow the instructions given 
                            <a target="_blank" href="http://pecl.php.net/package/oauth"> here </a> for installing the Oauth module.
                            </div><br />
                            <div> Add the OAuth Consumer Key and OAuth Consumer Secret of your application to config.php file </div> </br>
                            <div> Click on the button below to connect this app to QuickBooks
                            </div>';
                      // print connect to QuickBooks button to the page
                      echo "<br /> <ipp:connectToIntuit></ipp:connectToIntuit><br />";
                    } else {
                       echo "<h3>You are currently authenticated!</h3>";
                       $token = unserialize($_SESSION['token']);
                       echo "If not already done, please make sure that you set the below variables in the app.config file, before proceeding further! <br />";
                       echo "<br />";
                       echo "realm ID: ". $_SESSION['realmId'] . "<br />";
                       echo "oauth token: ". $token['oauth_token'] . "<br />";
                       echo "oauth secret: ". $token['oauth_token_secret'] . "<br />";
                       echo "<br />";
                       echo "<button class='myButton' title='App Home Page' onclick='myFunction($value)'>Go to the app</button>";
                       echo '&nbsp;&nbsp;&nbsp;';
                       echo "<button class='myButton' title='Disconnect your app from QBO' onclick='Disconnect($value)'>Disconnect the app</button>";
                       echo '&nbsp;&nbsp;&nbsp;';
                       echo "<button class='myButton' title='Regenerate the tokens within 30 days prior to token expiration' onclick='Reconnect($value)'>Reconnect the app</button>";
                       echo "<br />";
                       echo "<br />";
                       echo "<br />";
                       echo '<div> <small> <u> Note:</u> Configuring the Oauth tokens manually in app.config file is only for demonstartion purpose in this sample app. In real time production app, save the oath_token, oath_token_secret, and realmId in a persistent storage, associating them with the user who is currently authorizing access. Your app needs these values for subsequent requests to Quickbooks Data Services. Be sure to encrypt the access token and access token secret before saving them in persistent storage.<br />
                             Please refer to this <a target="_blank" href="https://developer.intuit.com/docs/0050_quickbooks_api/0020_authentication_and_authorization/connect_from_within_your_app"> link </a>for implementing oauth in your app. </small></div> <br />'; 
                      }
        }
    } catch(ErrorException $e) {
        echo $e->getMessage();
    }
    ob_end_flush();
?>
<script>
function myFunction(parameter){
window.location.href = "http://localhost/PHPSample/SampleAppHomePage.php";
}

function Disconnect(parameter){
window.location.href = "http://localhost/PHPSample/Disconnect.php";
}

function Reconnect(parameter){
window.location.href = "http://localhost/PHPSample/Reconnect.php";
}
</script>
</body>
</html>

Could someone point out what did i miss?

jameshwart lopez
  • 2,993
  • 6
  • 35
  • 65
  • This question is all about third part code support and you need contact their support center of [appcenter.intuit.com](https://appcenter.intuit.com/constantcontact?cid=ipp_ConContact_home_herobannerJuly2016#support). – AddWeb Solution Pvt Ltd Oct 27 '16 at 06:23
  • @AddWebSolutionPvtLtd thanks for the recommendation but it seems like its not what im looking for. What I really want to do is get the users firstname and last name when a user hits getapps now. do you have other idea to do it? – jameshwart lopez Oct 27 '16 at 08:50
  • Silly question perhaps... but have you checked that first and last names have been filled out? Many times just a username & nickname are provided – K Scandrett Nov 03 '16 at 04:33
  • And does `namePerson/friendly` provide a value? – K Scandrett Nov 03 '16 at 04:35
  • @KScandrett It doesn't have. I can only see firstname which is 'namePerson' and the email which is 'contact/email'. – jameshwart lopez Nov 03 '16 at 04:39
  • @KScandrett if I remove all required keys except 'contact/email' and 'namePerson' I get the same results in my print_r. – jameshwart lopez Nov 03 '16 at 04:44
  • Have you manually logged into the apps.com website and checked that there is a first and last name given? If there's nothing there then nothing will show (same with `namePerson/friendly` which will be blank if they haven't given a nickname) – K Scandrett Nov 03 '16 at 04:47
  • Yup, I have check that one also. Im sorry if it seems like a silly question but after checking my name and first name in apps.com, I can't think of any thing after that. – jameshwart lopez Nov 03 '16 at 04:49
  • 1
    My "Silly question" was about MY question, not yours. Your question is fine :) – K Scandrett Nov 03 '16 at 04:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/127239/discussion-between-jameshwart-lopez-and-k-scandrett). – jameshwart lopez Nov 03 '16 at 04:53
  • What this line prints `print_r($openid->getAttributes());` ? – Hackerman Nov 07 '16 at 17:43
  • only show email and the first name event though i have those many required keys @Hackerman – jameshwart lopez Nov 11 '16 at 07:54

0 Answers0