slim PHP Get parameters - web-services

get attributes from the URI using Slim 2 Framwork
http://localhost:8080/serverEndModule1/v1/varifyid=OQ==&code=1e212ffc375e52a9c6e7debe8adcc17
using the following Code:
$app->get('/varify', function () use ($app) {
$id = $app->request->get('id');
$paramValue2 = $app->request->get('code');
$db = new DbOperation();
$response = array();
$db->userVarify($id, $code); // send to database
help me to implement the following $app->get route .

Thanks I got it now it' working
$app->get('/varify', function() use ($app){
$req = $app->request();
$id = $req->get('id'); //
$code = $req->get('code');
$db = new DbOperation();
$response = array();
$res= $db->userVarify($id, $code);
}

Related

How can I get email from Google People API?

I am using Google people API client library in PHP.
After successfully authenticating, I want to get email
Help me to find out the problem from my code below.
Can i use multiple scopes to get email, beacuse when i m using different scope it gives me error
function getClient() {
$client = new Google_Client();
$client->setApplicationName('People API');
$client->setScopes(Google_Service_PeopleService::CONTACTS);
$client->setAuthConfig('credentials.json');
$client->setAccessType('offline');
$client->setPrompt('select_account consent');
$str = file_get_contents('credentials.json');
$json = json_decode( $str, true );
$url = $json['web']['redirect_uris'][0];
if (isset($_GET['oauth'])) {
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect_uri = $url;
header('Location: ' . filter_var($redirect_uri,FILTER_SANITIZE_URL));
} else if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$people_service = new Google_Service_PeopleService($client);
} else {
$redirect_uri = $url.'/?oauth';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
return $people_service;
}
$optParams = array(
'pageSize' => 100,
'personFields' => 'addresses,ageRanges,biographies,birthdays,braggingRights,coverPhotos,emailAddresses,events,genders,imClients,interests,locales,memberships,metadata,names,nicknames,occupations,organizations,phoneNumbers,photos,relations,relationshipInterests,relationshipStatuses,residences,sipAddresses,skills,taglines,urls,userDefined',
);
$people_service = getClient();
$connections = $people_service->people_connections-
>listPeopleConnections('people/me', $optParams);

facebook registration plugin location field not writing to mysql

Everything else works fine except for the location. The actual city/state does not come across. Instead the word Array is displayed. My field type in the database is text but I've tried every field type through mysql. The HTML file is JSON where it comes to the field names. I am very new at this so any help is appreciated.
This is my php file:
<? ob_start(); ?>
<?php
define('FACEBOOK_APP_ID', '');
define('FACEBOOK_SECRET', '');
// No need to change function body
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
if ($_REQUEST) {
$response = parse_signed_request($_REQUEST['signed_request'],
FACEBOOK_SECRET);
/*
echo "<pre>";
print_r($response);
echo "</pre>"; // Uncomment this for printing the response Array
*/
$name = $response["registration"]["name"];
$email = $response["registration"]["email"];
$gender = $response["registration"]["gender"];
$prosecutor = $response["registration"]["prosecutor"];
$location = $response["registration"]["location"];
// Connecting to Database
$con = mysql_connect("my_hosting_site","Database","password");
if (!$response)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Database", $con);
mysql_query("INSERT INTO my_table (name, email, gender, prosecutor, location)
VALUES ('$name', '$email', '$gender', '$prosecutor', '$location')");
mysql_close($con);
}
$URL="https://www.facebook.com";
header ("Location: $URL");
?>
<? ob_flush(); ?>
Facebook
Basically, it's an array.
[location] => Array
(
[name] => Delhi, India
[id] => 1.1604xxxxxx286E+14
)
Use this for getting location stored in your db, like I have written below:
$location = $response["registration"]["location"]["name"];

Class 'EventManager' not found

I'm trying to learn about Events in Doctrine, but when I read the docs, I get stuck at the very first line:
$evm = new EventManager();
Here I get a
PHP Fatal error: Class 'EventManager' not found
How can I solve this issue?
Here is the complete code:
use Doctrine\ORM\Tools\Setup;
require_once("Doctrine/ORM/Tools/Setup.php");
Setup::registerAutoloadPEAR();
$classLoader = new Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$paths = array();
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$dbParams = array("driver" => "pdo_mysql",
"host" => variable_get("dbManip_host"),
"user" => variable_get("dbManip_user"),
"password" => variable_get("dbManip_password"),
"dbname" => variable_get("dbManip_dbName"),
"charset" => "utf8");
global $entityManager_globalObject;
$entityManager_globalObject = \Doctrine\ORM\EntityManager::create($dbParams, $config);
$entityManager_globalObject->getConnection()->exec("SET NAMES UTF8");
$evm = new EventManager();
You are looking for class Doctrine\Common\EventManager.
$evm = new \Doctrine\Common\EventManager();
or
use Doctrine\Common\EventManager; // at the top of your file
$evm = new EventManager();

Webservice Add/Update Combinations Prestashop

I read, i try, i looking informations about how add / update combinations by webservice, in presta 1.5.3 but still i don't know how to do that.
Can someone help me?
Assigning combinations to products via Webservice is a multi-step operation (unlike CSV import).
given a product with id_product
add product_options (BO Attribute Names)
add product_option_values (BO Attribute Values) to product_options
add combinations while specifying id_product
Start by initialising PrestaShopWebservice with DEBUG=true:
$api = new PrestaShopWebservice($psShopUrl, $psAuthKey, $psDebug);
Instead of building the XML from scratch get a template for the resource you need like this:
$sxml = $api->get(array('url' => $psShopUrl.'api/'.$resource.'?schema=blank'));
The response is a SimpleXMLElement which is a easier to manipulate than DOM.
NB: The response contains all wrapper nodes and you must send the same back in your request i.e. PSWebServiceLibrary will not recreate them for you.
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<combination>
...
</combination>
</prestashop>
SXML manipulation example:
$schema = $api->get(array('url' => $psShopUrl.'api/product_options?schema=blank'));
$data = $schema->children()->children();
$data->is_color_group = false;
$data->group_type = $group_type; // radio, select
$data->name->language[0] = 'attribute private name';
$data->public_name->language[0] = 'attribute public name';
$xml = $schema->asXML(); // all of it!
$ret = $api->add(array('resource' => 'product_options', 'postXml' => $xml));
$id_attribute_group = (int)$ret->children()->children()->id; // save for next step
Then get product_option_values schema, set data and the id_attribute_group from previous step. And so on.
Updating is the same except you will get the resource by id and then edit:
$sxml = $api->get(array('resource' => $resource, 'id' => $id));
...
$ret = $api->edit(array('resource' => $resource, 'id' => $id, 'putXml' => $xml));
As for adding multiple id values to the product_option_values node in the combinations resource you can use the array_push shortcut []:
$data->associations->product_option_values->product_option_values[]->id = 123;
$data->associations->product_option_values->product_option_values[]->id = 456;
This is work fine for me :
$webService = new PrestaShopWebservice($url, $api_key, FALSE);
$xml = $webService->get(array('url' => $url .'/api/combinations?schema=blank'));
$resources = $xml->children()->children();
$resources->id_product = $ps_product_id;
$resources->wholesale_price = $wholesale_price;
$resources->price = $price;
$resources->unit_price_impact = $unit_price_impact;
$resources->minimal_quantity = $minimal_quantity;
$resources->quantity = $quantity;
$resources->weight = $weight;
$resources->associations->product_option_values->product_option_value[0]->id = $color_id;
$resources->associations->product_option_values->product_option_value[1]->id = $size_id;
$request = $xml->asXML();
//This is a function that curl request to specific URL using method (POST)
$response = ps_curl($url . '/api/combinations', $request, 'POST', $api_key);
$xml_load = simplexml_load_string($response);
$id = $xml_load->combination->id;
I hope that's helpful :)

Is there any way to get facebook user email with django-facebookconnect?

I already integrate django-facebookconnect on my project, but when user login email field stay empty, i mean this app does not save user email ??
It seems like it does:
user = User(username=request.facebook.uid,
password=sha.new(str(random.random())).hexdigest()[:8],
email=profile.email)
But when i check it does not saves email, is this an error or a facebook restriction?
You need to get the extended permission from facebook.
<?php
$app_id = "YOUR_APP_ID";
$app_sec = "APP_SEC";
$canvas_page = "APP_CANVAS_PAGE_URL";
$scope = "&scope=user_photos,email,publish_stream"; $auth_url"http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($canvas_page).$scope;
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode(".", $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, "-_", "+/")), true);
if (empty($data["user_id"])) {
echo(""); }
$access_token = $data["oauth_token"];
$user_id = $data["user_id"];
$user = json_decode(file_get_contents( "https://graph.facebook.com/me? access_token=" . $access_token));
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($COOKIE["fbs" . $app_id], "\""), $args);
ksort($args);
$payload = "";
foreach ($args as $key => $value) {
if ($key != "sig") {
$payload .= $key . "=" . $value;
}
}
if (md5($payload . $application_secret) != $args["sig"]) {
return null;
}
return $args;
}
$cookie = get_facebook_cookie($app_id, $app_sec);
?>