How to use the Firebase to send data to my PHP code - php

I am working with arduino project and I used PHP to connect to the Firebase.
I want to receive a data from firebase using PHP. I want the $new_ssid and $new_password to received from Firebase.
Here's my code:
<?php
require 'firebaseLib.php';
$Trash = $_GET["trash"];
$Distance = $_GET["distance"];
$Temperature = $_GET["temp_f"];
$Humidity= $_GET["humidity"];
$baseURI = 'x';
$token = 'x';
$devicestatus= array('Distance' => $Distance,'Temperature' =>
$Temperature,'Humidity' => $Humidity);
$firebasePath = '/x/';
$full= array($Trash => $devicestatus);
$fb = new Firebase($baseURI, $token);
$fb -> update($firebasePath, $full);
$new_ssid = "arduino";
$new_pass = "mechanical";
echo $new_ssid."/".$new_pass ;
?>

Related

Strava Api issue

I'm using this composer package https://github.com/basvandorst/StravaPHP
The OAUTH is working fine and its generating me the JSON with the access token and user id, etc..
But whenever I try to use other function it returns me 404 not found.
Output is this :
{"token_type":"Bearer","access_token":"077058e0c800881c72a4b10a04a520d5898d4e3e","athlete":{"id":35670467,"username":"amir_do","resource_state":2,"firstname":"Amir","lastname":"Do","city":null,"state":null,"country":null,"sex":"M","premium":false,"summit":false,"created_at":"2018-10-13T13:55:41Z","updated_at":"2018-10-13T13:56:25Z","badge_type_id":0,"profile_medium":"https://lh5.googleusercontent.com/-ku6v9lKNgYY/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbASj8KhClhwnVYVqRrEG2oiYzWPbA/mo/photo.jpg","profile":"https://lh5.googleusercontent.com/-ku6v9lKNgYY/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbASj8KhClhwnVYVqRrEG2oiYzWPbA/mo/photo.jpg","friend":null,"follower":null,"email":"goncalomaia97#gmail.com"}}
35670467
Client error: `GET https://www.strava.com/api/athletes/35670467/stats?access_token=077058e0c800881c72a4b10a04a520d5898d4e3e` resulted in a `404 Not Found` response: {"message":"Record Not Found","errors":[{"resource":"resource","field":"path","code":"invalid"}]}
And this is my current callback.php page code:
<?php
include 'vendor/autoload.php';
use Strava\API\Client;
use Strava\API\Exception;
use Strava\API\Service\REST;
session_start();
$client = new GuzzleHttp\Client();
global $connect;
require_once("configs/database.php");
$connect = new mysqli($config['database']['host'],$config['database']['user'],$config['database']['pass'],$config['database']['db']);
$code = $_GET['code'];
$state = $_GET['state'];
$scope = $_GET['scope'];
$user = $_SESSION['username'];
$check = $connect->query("SELECT * FROM users WHERE email = '$user'");
$fetch = $check->fetch_array(MYSQLI_ASSOC);
$apix = $fetch['api'];
$api_secretx = $fetch['api_secret'];
$client = new GuzzleHttp\Client();
$data = [
"client_id" => $apix,
"client_secret" => $api_secretx,
"code" => $code
];
$result = $client->post('https://www.strava.com/oauth/token', ['json' => $data]);
print "<pre>";
print_r( $result->getBody()->getContents() );
print "</pre>";
$bodyb = $result->getBody();
$varx = json_decode((string) $bodyb, true);
$token = $varx['access_token'];
$id = $varx['athlete']['id'];
$_SESSION['token'] = $token;
printf($id);
try {
// REST adapter (We use `Guzzle` in this project)
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3']);
// Service to use (Service\Stub is also available for test purposes)
$service = new \Strava\API\Service\REST($token, $adapter);
// Receive the athlete!
$client = new Client($service);
$athlete = $client->getAthleteStats($id);
print_r($athlete);
} catch(Exception $e) {
print $e->getMessage();
}
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3']);
Change that to this (It should be trailing) :
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3/']);

Get last tweet Twitter api

I try to show the last tweet from a specif user, using the Twitter API. When I try to echo the first result I get an empty page. When I echo my JSON data is see this.
I have the following PHP script:
<?php
require "Twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
$consumer_key = "";
$consumer_secret = "";
$access_token = "";
$access_token_secret = "";
$connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");
$statuses = $connection->get("statuses/user_timeline", ["screen_name" => "NS_online"], ["lang" => "NL"]);
//var_dump($statuses);
// get your json as an associative array
$jsonArray = json_decode($statuses, true);
print_r($jsonArray);
$test = $jsonArray[0]->created_at;
echo $test;
?>

using twilio account how to create a dynamic conference call for voiceurl in php

I am trying to upload using client on twilio and trying buy a twilio number.
Also, I need to get a dynamic voice URL in order to record a conference call dynamically.
<?php
require_once 'vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "*********************";
$token = "*******************";
$client = new Client($sid, $token);
$numbers = $client->availablePhoneNumbers('US')->local->read(
array("areaCode" => "424")
);
$twilioNumber = $numbers[0]->phoneNumber;
$newNumber = $client->incomingPhoneNumbers->create(
[
"voiceUrl" => "host url",
"voiceMethod" => "GET"
]
);
if ($newNumber) {
return $twilioNumber;
} else {
return 0;
}
//
In the voiceUrl parameter i am passing a conference call connect code hosted link but its not getting updated to twilio account dynamically.
You can use like
require 'Services/Twilio.php';
$account_id = ACCOUNT_SID;
$auth_token = AUTH_TOKEN;
$number = $_REQUEST['id'];
$client = new Services_Twilio($account_id, $auth_token);
try{
$number= $client->account->incoming_phone_numbers->create(array('PhoneNumber' =>'+'.$number));
$number_sid=$number->sid;
$number1 = $client->account->incoming_phone_numbers->get($number_sid);
$number1->update(array("VoiceUrl" => "http://11.11.1.111/test/twilio_call_response.php","SmsUrl"=>"http://11.11.1.111/test/incomingsms.php","VoiceFallbackUrl"=>"http://11.11.1.111/test/fall_backurl.php"));
$phone_number=str_replace('+','',$numbers);
$allocate='1';
}catch(Exception $e){
echo $err = "Error purchasing number: {$e->getMessage()}";
}
echo $phone_number;

Convert PHP SoapClient to Perl SOAP::Lite

I am writing a web application that works with the five9 API. I have a working php script that uses the API to print out the email of the first User. My application is in Perl and I am trying to avoid shelling out to a PHP script. I have tried to use SOAP::Lite but am having difficulties. Here is my working PHP script.
#!/usr/bin/php
<?php
$soap = null;
$wsdl = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl";
$user = "johnsmith#example.com";
$pass = "password";
$soap_options = array("login" => $user, "password" => $pass, "trace" => 1);
$soap = new SoapClient($wsdl, $soap_options);
$arryParams['userNamePattern'] = '';
$result = $soap->getUsersInfo($arryParams);
if(isset($result->return)) {
$objRecords = $result->return;
print $objRecords[0]->generalInfo->EMail;
print "\n";
}
?>
Here is what I have so far working with perl and SOAP::Lite
#!/usr/bin/env perl
use warnings;
use strict;
use MIME::Base64;
use Data::Dumper;
use SOAP::Lite +trace => [ transport => sub { print $_[0]->as_string } ];
my $wsdl_five9 = 'https://api.five9.com/wsadmin/AdminWebService?wsdl&user=johnsmith#example.com';
my $uri = 'https://api.five9.com/wsadmin/AdminWebService';
my $user = 'johnsmith#example.com';
my $password = 'password';
my $authorize = 'Basic '.encode_base64($user . ":" . $password);
my $client = SOAP::Lite->service($wsdl_five9);
$client->on_fault(
sub {
my $soap = shift;
my $res = shift;
if(ref($res) eq '') {
die($res);
} else {
die($res->faultstring);
}
return new SOAP::SOM;
}
);
print "Done\n";
If anyone has experience working with perl and SOAP any insight would be greatly appreciated.

How do you get user OAuth for the Tumblr API in PHP?

Using the default Tumblr v2 API, I'm able to connect to my application, and retrieve posts from my own account. However, I'd like users to be able to connect their own accounts. I've tried to figure this out but I'm not entirely sure how to use OAuth (im using this class). How is this done?
The code I'm using to retrieve dashboard posts is:
$consumerKey = 'xxx';
$consumerSecret = 'xxx';
$tumblr = new Tumblr\API\Client(
$consumerKey,
$consumerSecret
);
var_dump( $tumblr->getDashboardPosts() ); // using var_dump for testing purposes only
This code works, but it's only returning the code for my PERSONAL account.
I figured it out, thanks to Github user seejohnrun.
require_once 'include/util.php';
$consumerKey = 'XXX';
$consumerSecret = 'XXX';
$client = new Tumblr\API\Client($consumerKey, $consumerSecret);
$requestHandler = $client->getRequestHandler();
$requestHandler->setBaseUrl('https://www.tumblr.com/');
// If we are visiting the first time
if (!$_GET['oauth_verifier']) {
// grab the oauth token
$resp = $requestHandler->request('POST', 'oauth/request_token', array());
$out = $result = $resp->body;
$data = array();
parse_str($out, $data);
// tell the user where to go
echo ' GO ';
$_SESSION['t']=$data['oauth_token'];
$_SESSION['s']=$data['oauth_token_secret'];
} else {
$verifier = $_GET['oauth_verifier'];
// use the stored tokens
$client->setToken($_SESSION['t'], $_SESSION['s']);
// to grab the access tokens
$resp = $requestHandler->request('POST', 'oauth/access_token', array('oauth_verifier' => $verifier));
$out = $result = $resp->body;
$data = array();
parse_str($out, $data);
// and print out our new keys we got back
$token = $data['oauth_token'];
$secret = $data['oauth_token_secret'];
echo "token: " . $token . "<br/>secret: " . $secret;
// and prove we're in the money
$client = new Tumblr\API\Client($consumerKey, $consumerSecret, $token, $secret);
$info = $client->getUserInfo();
echo "<br/><br/>congrats " . $info->user->name . "!";
}

Categories