Unable to get FirstName and LastName from openid attributes - php

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 />Sign Out';
//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 ' ';
echo "<button class='myButton' title='Disconnect your app from QBO' onclick='Disconnect($value)'>Disconnect the app</button>";
echo ' ';
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?

Related

How to edit a received xml file and send over http with php?

I'm have to build a "simple" application that will reads an xml file, prompts a user to choose a "response activity" in relation to what's on that file and send the whole thing (what was loaded + the activity chosen by the user) to a client over http in a new xml file.
So my questions is:
how can i add what's been loaded as well as the user chosen response activity onto a new xml file? and how do i send it to anyaddress.com?
i've also been told to use rest webservices, and although i have found a lot of information and examples online, nothing seem to be relevant to what i'm trying to do.
As you may have guessed, i'm new to all this. here' what i've done so far:
<?php
//reader.php
// Load the xml file and show what's on it
$xml = simplexml_load_file('xmlfile.xml')
or die("Could not open file!<hr /> ");
foreach($xml->children() as $child) {
foreach($child->children() as $young) {
echo $young->getName() . ": " . $young . "<br />";
}
}
// call the activity list according to what's on the xml file
if ($child->ACTIVITY == 'activity import') {
echo "<br/>" . file_get_contents('interface.php');
}
elseif($child->ACTIVITY == 'activity import special'){
echo "<br/>" . file_get_contents('interface1.php');
}
elseif($child->ACTIVITY == 'activity export'){
echo "<br/>" . file_get_contents('interface2.php');
}
else {
echo "<br/>" . 'incorrect activity';
}
// print the selected activity on page
if (isset($_POST['submit1'])) {
$selected_radio = $_POST['group1'];
print $selected_radio;
}
?>
this is one of the 3 forms i have for user input interface2.php
<form name="serv1" action="reader.php" method="POST">
<div align="left"><br>
<input type="radio" name="group1" value="OUTBOUND"> OUTBOUND<br/>
<input type="radio" name="group1" value="DONTPROCESS" checked> DON'T PROCESS<br/><br/>
<input type="submit" name="submit1" value="Return">
</div>
</form>
Any kind of help will be much appreciated.
You can perform edits on an XML file e.g. with SimpleXML or with DOMDocument.
You could post the result to another server with CURL.

Trouble retrieving friends data from Facebook API

I am trying to:
Retrieve a friend list from a user with the friend information:
Location
Education
Name
Profile picture
The problem is the standard permissions given only has friend profile picture and name. I used this to get the other information:
$params = array(
'scope' => 'email, friends_likes, user_about_me, friends_about_me, friends_location, friends_website, friends_work_history, friends_education_history'
);
$loginUrl = $facebook->getLoginUrl($params);
}
So now when I log in on my page, Facebook asks me if I'm willing to give those permissions to the application, so that is a good sign.
The problem is I'm still not able to figure out how to get the information. When I try and do
print_r($friends);
or
print_r($friends["data");
I still just get an array with name and ID.
Why am I not seeing the extra information?
This is not the full code, but a lot of it (most came from the example.php from the main Facebook GitHub account):
<?php
if ($user):
echo "Name: " . $user_profile['name']; ?> <br />
<?php echo "Location: " . $user_profile['location']['name']; ?> <br />
<?php echo "Bio: " . $user_profile['bio']; ?> <br />
<?php
foreach($user_profile['work'] as $work) {
echo "Work: " . $work['employer']['name'];?><br />
<?php echo "Position: " . $work['position']['name'];?><br />
<?php
}
?>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture?type=large">
<h3>Your User Object (/me)</h3>
<pre><?php
print_r($friends);
?></pre>
<?php
echo '<ul>';
foreach ($friends["data"] as $value) {
echo '<li>';
echo '<div class="pic">';
echo '<img src="https://graph.facebook.com/' . $value["id"] . '/picture?type=large"/>';
echo '</div>';
echo '<div class="picName">'.$value["name"].'</div>';
echo '<div class="location">'.$value["location"]["name"];
echo '<div class="bio">'.$value["bio"];
echo '</div>';
echo '</li>';
}
echo '</ul>';
?>
The API call (note I made the $permissions just for testing to be sure I was getting it, and they are showing up).
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
$permissions = $facebook->api('/me/permissions');
$friends = $facebook->api('/me/friends');
}
catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
Your API call to /me/friends is incorrect. You need to do something like:
$friends = $facebook->api('me/friends?fields=birthday,location,about...');
You need to add in the extra fields you require as parameters in the API call. I've added a few in the above example, but you will need to add the remaining ones.

Using Snoopy PHP class in Drupal

I really don't know Drupal but have managed to create a simple HTML page that I would like to use the first and last name inputted to run snoopy.class.php to run a script on a web site to retrieve some data. The button should run a function that will submit the URL but I am not getting any results.
Because I don't know how to debug in Drupal I added some echo statements to see how far the code ran it seems to be stopping when it tries to create a new snoopy object. I downloaded the class and put it in what I would think would be an accessible folder, namely public_html/tools it:
-rw-r--r-- 1 agentpitstop apache 37815 Sep 3 21:03 Snoopy.class.php
Below is the code I am using
<form method="post">
<p>Last Name: <input type="text" name="lastname" /><br />
First Name: <input type="text" name="firstname" /></p>
<p><input type="submit" value="Send it!"></p>
</form>
<?php
if($_POST)
{
echo "1st display <br />\n";
$url = "https://pdb-services-beta.nipr.com/pdb-xml-reports/hitlist_xml.cgi?";
$url = $url . "customer_number=beta83agent&pin_number=nipr123&report_type=1";
$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
$parms = array("name_last"=>$lastname,"name_first"=>$firstname);
echo "2nd display <br />\n";
$result = curl_download($url,$parms);
$xml=simplexml_load_file("$result.xml");
$nipr_id = $xml->NPN;
echo "url " . $url . "<br />\n";
echo "Agent " . $_POST['firstname'] . " " . $_POST['lastname'] . " Id is:". $nipr_id . "<br />\n";
echo "3rd Result from call " . $result . "<br />\n";
}
?>
<?php
include "Snoopy.class.php";
function curl_download($url,$parms)
{
echo "in call to curldownload ";
$snoopy = new Snoopy();
echo "after setting object";
$snoopy->curl_path = "/usr/bin/curl"; # Or whatever your path to curl is - 'which curl' in terminal will give it to you. Needed because snoopy uses standalone curl to deal with https sites, not php_curl builtin.
echo "after setting path";
$snoopy->httpsmethod = "POST";
echo "after setting post";
$snoopy->submit($url, $parms);
echo "after setting submit";
print $snoopy->results;
echo "results: " . results;
return $snoopy->results;
}
?>
Any help would be appreciated.
If you need custom development on a Drupal site create a custom module and use Drupal's form API.
If you need to perform HTTP request from PHP, use a PHP library/extension, such a php-curl, Guzzle or Drupal's drupal_http_request(). And yes, they all support HTTPS.

Unable to store the Facebook profile picture in sql database

As you can see the code below retrieve and shows all the required information from a Facebook profile..
Access Token:
User ID:
Name: Aneesh
First Name:
Last Name:
Email:
Gender:
Birthday:
Location: N
Time Zone:
but i am not able to store the profile picture in sql database ?
<?php
require 'lib/db.php';
require 'lib/facebook.php';
require 'lib/fbconfig.php';
session_start();
$facebook=$_SESSION['facebook'];
$userdata=$_SESSION['userdata'];
$logoutUrl=$_SESSION['logout'];
$access_token_title='fb_'.$facebook_appid.'_access_token';
$access_token=$facebook[$access_token_title];
if(!empty($userdata))
{
echo '<h1>Login User Details</h1>';
echo '<img src="https://graph.facebook.com/'.$userdata['id'].'/picture">';
At the moment the above the code displays the image...but how to store is the problem
I used BLOB which showed error
echo "<br/>";
echo '<b>Access Token: </b>'.$access_token;
echo "<br/>";
echo '<b>User ID: </b>'.$userdata['id'];
echo "<br/>";
echo '<b>Name: </b>'.$userdata['name'];
echo "<br/>";
echo '<b>First Name: </b>'.$userdata['first_name'];
echo "<br/>";
echo '<b>Last Name: </b>'.$userdata['last_name'];
echo "<br/>";
echo '<b>Email: </b>'.$userdata['email'];
echo "<br/>";
echo '<b>Gender: </b>'.$userdata['gender'];
echo "<br/>";
echo '<b>Birthday: </b>'.$userdata['birthday'];
echo "<br/>";
echo '<b>Location: </b>'.$userdata['location']['name'];
echo "<br/>";
echo '<b>Time Zone: </b>'.$userdata['timezone'];
echo "<br/>";
echo "<br/>";
$facebook_id=$userdata['id'];
$name=$userdata['name'];
$email=$userdata['email'];
$gender=$userdata['gender'];
$birthday=$userdata['birthday'];
$location=mysql_real_escape_string($userdata['location']['name']);
$hometown=mysql_real_escape_string($userdata['hometown']['name']);
$bio=mysql_real_escape_string($userdata['bio']);
$relationship=$userdata['relationship_status'];
$timezone=$userdata['timezone'];
$inserty = "INSERT INTO `users` (`facebook_id`, `name`, `email`, `gender`, `birthday`, `location`,`timezone`, `access_token`,`??????`)
VALUES ('$facebook_id','$name','$email','$gender','$birthday','$location','$timezone','$access_token',`?????`)";
mysql_query($inserty, $connection);
????? I meant column for image
echo "<br/>";
echo 'Logout Facebook';
echo 'Logout Facebook';
include('status_update.php');
}
else
{
header("Location: fblogin.php");
}
?>
It sounds like you are trying to store the binary data for the image itself, instead of the URL to the image. Ideally, you shouldn't store the image / URL as it's ever-changing on Facebook. Depending on the user, it may change everyday! You can get the current image easily using the API or Facebook ID.
If you must store it, you should store the URL to the Facebook version rather than the image itself.
If you still want to store the image in the DB, try using the BINARY type instead.

Problem with require_once in a hello world facebook app

Im new to developing facebook apps.I have the following issue and would be glad if someone could help.
I have registered my app on facebook and uploaded the code and php client library to the hosting server. If i use the code below then everything works fine.
<?php
require_once('./facebook/php/facebook.php');
/* initialize the facebook API with your application API Key
and Secret */
$facebook = new Facebook("<my_api_key>","<my_secret_key>");
$user = $facebook->require_login();
echo "<p>Your User ID is: $user</p>";
echo "<p>Your name is: <fb:name uid=\"$user\" useyou=\"false\"/></p>";
echo "<p>You have several friends: </p>";
$friends = $facebook->api_client->friends_get();
echo "<ul>";
foreach ($friends as $friend) {
echo "<li><fb:name uid=\"$friend\" useyou=\"false\" /></li>";
}
echo "</ul>";
/* Echo some information that will
help us see what's going on with the Facebook API: */
echo "<pre>Debug:" . print_r($facebook,true) . "</pre>";
?>
But, if i divide the code into two files as follows then i just get a blank canvas when i navigate to http://apps.facebook.com/myapp
appinclude.php
<?php
require_once('./facebook/php/facebook.php');
/* initialize the facebook API with application API Key
and Secret */
$facebook = new Facebook("<my_api_key>","<my_secret_key>");
$user = $facebook->require_login();
?>
index.php
<?php
require_once('./appinclude.php');
echo "<p>Your User ID is: $user</p>";
echo "<p>Your name is: <fb:name uid=\"$user\" useyou=\"false\"/></p>";
echo "<p>You have several friends: </p>";
$friends = $facebook->api_client->friends_get();
echo "<ul>";
foreach ($friends as $friend) {
echo "<li><fb:name uid=\"$friend\" useyou=\"false\" /></li>";
}
echo "</ul>";
/* Echo some information that will
help us see what's going on with the Facebook API: */
echo "<pre>Debug:" . print_r($facebook,true) . "</pre>";
?>
Any way to fix this ?
Thank You.
The way I set up my app is to have all the files in the same directory so there is no confusion.
/Myapp/index.php
<?php
require_once('appinclude.php');
?>
/Myapp/appinclude.php
<?php
require_once('facebook.php');
?>
The Myapp directory looks like this:
/Myapp/jsonwrapper/JSON/JSON.php
/Myapp/jsonwrapper/JSON/LICENSE
/Myapp/jsonwrapper/jsonwrapper.php
/Myapp/jsonwrapper/jsonwrapper_inner.php
/Myapp/facebook.php
/Myapp/facebookapi_php5_restlib.php
/Myapp/appinclude.php
/Myapp/index.php
In your second example the layout would need to be like this to work:
/facebook/php/facebook.php
/Myapp/AnotherDirectory/index.php
/Myapp/appinclude.php
Notice the appinclude.php and index.php are not in the same folder. index.php looks for a file appinclude.php in the directory above itself, and appinclude.php looks for a file facebook/php/facebook.php in the directory above itself. If you were to remove the dots and slashes from the front of the require statements it would look for it all in the same directory. Basically what you need to realize is that the ./ in require_once('./appinclude.php'); says look in the directory above this one.
I would check file paths.
It seems in your second (non-working version) you're trying to include a file from a directory called 'facebook/php/'.
If this is the directory that you've specified as your application's root then I would guess Facebook won't allow you to include files below that directory level.

Categories