Having read documentations and tutorials for hours, I ended up in more confusion after all. So, here I'm asking for your help/tips and I'd really appreciate any effort helps me take a step further. Sorry for any mistakes I might possibly make, I'm quite newbie on this topic, so to say.
I'm building a web application, actually a single web page, that will start running as soon as it receives a GET/POST request from an external source. So, the page will be updated asynchronously if any request is received, for which I thought of using AngularJS and AngularFire on the front-end later on. I know there are many other ways and probably much simpler too, but I'm quite curious about how to integrate my CakePHP application with Firebase platform. So, let's stick with CakePHP + Firebase solutions for now.
So far, using the SDK Firebase PHP Client made much sense, however, I'm still confused about the files that needs to be manipulated. Since there are simply not many -I've found none so far- examples that use CakePHP3 Framework with Firebase, I'm stuck here and I'd really appreciate any help here. Firstly, this code is given in the link and I wonder how it works and what those vars and constants stand for.
const DEFAULT_URL = 'https://kidsplace.firebaseio.com/';
const DEFAULT_TOKEN = 'MqL0c8tKCtheLSYcygYNtGhU8Z2hULOFs9OKPdEp';
const DEFAULT_PATH = '/firebase/example';
$firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
// --- storing an array ---
$test = array(
"foo" => "bar",
"i_love" => "lamp",
"id" => 42
);
$dateTime = new DateTime();
$firebase->set(DEFAULT_PATH . '/' . $dateTime->format('c'), $test);
// --- storing a string ---
$firebase->set(DEFAULT_PATH . '/name/contact001', "John Doe");
// --- reading the stored string ---
$name = $firebase->get(DEFAULT_PATH . '/name/contact001');
And here is the main question, assuming that I have a test function on one of the end points of my application, let say www.example.com/visits/test, how do I make sure that my application is integrated to Firebase platform and any request sent to that end point is being listened continuously?
Here is how I solved it, just so you know. It's needed to add a test end point to the controller file that you're using. You can find your token using Project Settings in your project file. A quick example is below.
public function test()
{
$DEFAULT_URL = 'YOUR_URL';
$DEFAULT_TOKEN = 'YOUR_TOKEN';
$DEFAULT_PATH = '/';
$firebase = new \Firebase\FirebaseLib($DEFAULT_URL, $DEFAULT_TOKEN);
$lines = [
"I had a problem once",
"I used Java to solve it",
"Now, I have ProblemFactory",
];
foreach ($lines as $line) {
$foo = $firebase->push($DEFAULT_PATH."code/",$line);
echo "child_added";
sleep(0.1);
echo "<br> ";
}
Then, in order to capture the lines added on the front-end, you may use a code similar to the code below. You can easily reach the version that fits your code from your firebase console by clicking Add "firebase to your web app" button or sth like this.
<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"> </script>
<script>
// Initialize Firebase
var config = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR-DOMAIN",
databaseURL: "YOUR_URL",
storageBucket: "YOUR_BUCKET",
};
firebase.initializeApp(config);
var codeRef = firebase.database().ref('code/');
codeRef.on('child_added', function(data) {
console.log(data.val());
});
</script>
I'm not done with the app yet, however, this insight may help you deal with similar issues.
Related
I want to put my fortnite stats on my website HTML/CSS. I find this.
But I don't know php very good, so I need your help. Must I delete this: 'your_api_key' and put : your_api_key without the ' ' ?
And lines like this:
$this->auth = new Fortnite_Auth($this);
$this->challenges = new Fortnite_Challenges($this);
$this->leaderboard = new Fortnite_Leaderboard($this);
$this->items = new Fortnite_Items($this);
$this->news = new Fortnite_News($this);
$this->patchnotes = new Fortnite_PatchNotes($this);
$this->pve = new Fortnite_PVE($this);
$this->status = new Fortnite_Status($this);
$this->weapons = new Fortnite_Weapons($this);
$this->user = new Fortnite_User($this)
Must I modify something?
(here are some informations:
-user_id: 501b9f2dfda34249a2749467513172bf
-username: NoMaD_DEEPonion
-platform: pc
-windows: season 5
)
For all this code, I used xammp server (I hope it's good)
Thank you for your help
You should always quote '' your key/strings. So it would look like:
$api->setKey('123qwerty456');
$api->user->id('NoMaD_DEEPonion');
Please read their documentation. You're supposed to get an API key from them to get started. And you don't have to edit Client.php. You're supposed to include the files instead. Try including Autoloader.php, since it requires the necessary files.
XAMPP is alright for development, but not suitable for production/public. Good luck!
What #sykez wrote.
I personally use https://fortniteapi.com/ to get the data. They also have a sweet POSTMAN page with different requests https://documenter.getpostman.com/view/4499368/RWEjoGqD
At last. I am not really sure that this will be a good project to start learning PHP from. I really suggest that you get to understand the basics of PHP first before you jump into API calls, processing arrays and more.
I'm actually building a PHP bot that reads the youtube live streaming chat, and store in a Database the message that contains a specific keyword wrote by the users during the livestream. All the logic is in place, what is missing is the feedback on chat when the bot is "triggered".
I looked everywhere but seams the PHP documentation is missing, if you look inside the PHP Classes there is the public function insert, but there is no example at all on how to use it?
Someone know how to use it?
Should be something "simple" like: $result = $youtube->liveChatMessages->Insert($args); but I can't figure out on what args looks like.
HERE the only reference about the Insert method
Thanks to all for any suggestion on how to use it!
17/06/2018 edit Working Example
$liveChatMessage = new Google_Service_YouTube_LiveChatMessage();
$liveChatSnippet = new Google_Service_YouTube_LiveChatMessageSnippet();
$liveChatSnippet->setLiveChatId($liveChatID);
$liveChatSnippet->setType("textMessageEvent");
$messageDetails = new Google_Service_YouTube_LiveChatTextMessageDetails();
$messageDetails->setMessageText("Message to type in chat");
$liveChatSnippet->setTextMessageDetails($messageDetails);
$liveChatMessage->setSnippet($liveChatSnippet);
$videoCommentInsertResponse = $youtube->liveChatMessages->insert('snippet', $liveChatMessage);
I found a similar article here, but after a lot of testing, I'm still running into issues (Google API Data Transfer Insert: missing resource.applicationDataTransfer).
Essentially I'm trying to transfer ownership of a Google Drive to another person. I got this working for calendars (basically the same code, but different applicationId), but for the Drive, it says it completed without actually moving anything. I have verified that all of the API permissions are correct, and I've even been able to run this successfully in the Google API Explorer (https://developers.google.com/admin-sdk/data-transfer/v1/reference/transfers/insert?authuser=1).
Is there something really simple that I'm missing here?
$service = new Google_Service_DataTransfer($client); // $client is already defined and working properly
$oldUserID = 'oldAccountIdNumberHere';
$newUserID = 'newAccountIdNumberHere';
$driveTransferParams = new Google_Service_DataTransfer_ApplicationTransferParam();
$driveTransferParams->setKey("PRIVACY_LEVEL");
$driveTransferParams->setValue(['SHARED', 'PRIVATE']);
$driveDataTransfer = new Google_Service_DataTransfer_ApplicationDataTransfer();
$driveDataTransfer->setApplicationTransferParams($driveTransferParams);
$driveDataTransfer->applicationId = 'idStringForGoogleDriveAndDocs';
$driveTransfer = new Google_Service_DataTransfer_DataTransfer();
$driveTransfer->setNewOwnerUserId($newUserID);
$driveTransfer->setOldOwnerUserId($oldUserID);
$driveTransfer->setApplicationDataTransfers([$driveDataTransfer]);
$driveResults = $service->transfers->insert($driveTransfer);
My scopes for the client are: Google_Service_DataTransfer::ADMIN_DATATRANSFER,
Google_Service_DataTransfer::ADMIN_DATATRANSFER_READONLY
Thanks in advance!
Actually, I just figured it out. There were some parameters that needed to be passed within an array, and after doing that, it started working properly. Solution to my problem posted below in case it helps other people.
NOTE 1: see the setApplicationTransferParams line
NOTE 2: see the setApplicationId line
$service = new Google_Service_DataTransfer($client); // $client is already defined and working properly
$oldUserID = 'oldAccountIdNumberHere';
$newUserID = 'newAccountIdNumberHere';
$driveTransferParams = new Google_Service_DataTransfer_ApplicationTransferParam();
$driveTransferParams->setKey("PRIVACY_LEVEL");
$driveTransferParams->setValue(['SHARED', 'PRIVATE']);
$driveDataTransfer = new Google_Service_DataTransfer_ApplicationDataTransfer();
$driveDataTransfer->setApplicationTransferParams([$driveTransferParams]);
$driveDataTransfer->setApplicationId(['idStringForGoogleDriveAndDocs']);
$driveTransfer = new Google_Service_DataTransfer_DataTransfer();
$driveTransfer->setNewOwnerUserId($newUserID);
$driveTransfer->setOldOwnerUserId($oldUserID);
$driveTransfer->setApplicationDataTransfers([$driveDataTransfer]);
$driveResults = $service->transfers->insert($driveTransfer);
I want to retrieve data from database using mysql in codeigniter/custom php through text from my mobile.
I am student and new developer.
I'm going to try to point you in the right direction although a little research would take you there anyway. You should start by looking for an SMS API in php. A simple google search returns a lot of relevant results.
TextMagic is one such SMS Api and is hosted on https://code.google.com/. It is pretty well documented and quite simple to use:
$api = new TextMagicAPI(array(
"username" => "your_user_name",
"password" => "your_API_password",
));
$text = "Hello world!";
$phones = array(9991234567);
$is_unicode = true;
$api->send($text, $phones, $is_unicode);
So it's just about creating an account and it allows you to receive SMS as well.It all depends on how you want to go about it (if you are looking for a free or paid service and other features that you might want).
Anyway, I hope it gets you started in the right direction.
I am new to using WSDL's. I have used REST before but not this. I am trying to run the sample code file that is included on the UPS developer site. Page 23 of this guide is the API I am using. The file you can download includes like ten guides which I have perused, but I just initally want to figure out how to fill out the top configuration part below (I am using php example code file SoapRateClient.php). What do I put for WSDL? What do I put for end point url? The file you download on their site has several wsdl files and I'm not sure which one I am supposed to choose. Guidance appreciated.
<?php
//Configuration
$access = "secret";//I have this no problem
$userid = "";//I have this as well
$passwd = "";//I have this
$wsdl = " Add Wsdl File Here ";//What the heck do I put here!?
$operation = "ProcessRate";
$endpointurl = ' Add URL Here';//Also what do I put here?
$outputFileName = "XOLTResult.xml";
For anyone else out there confused on how to get started with the UPS Rate API, I implemented Jonathan Kelly's UPS Rate API class that he created. You just fill in your account number, key, username, password, and play with the other variables. I was able to return a dollar amount for ground shipping in five minutes. Thank gosh I didn't have to mess with SOAP and web services.
Here is details of top parameters for "SoapRateClient.php"
$access = "xxxx";
It is provided by the UPS.for this you have to create your account at UPS.This account is different from creating online account at the website.
https://www.ups.com/upsdeveloperkit
click on "Step 5: Request an access key."
2 $userid = "xxx";
userid of account.
3 $passwd = "xxx";
password of account
4 $wsdl = "wsdl/RateWS.wsdl";
this is the wsdl file you need to include for "SoapRateClient.php". Here change the path accordingly.
5 $operation = "ProcessRate";
value of operation to perform.
6
$endpointurl = 'https://wwwcie.ups.com/webservices/Rate';
I wish you the best of luck. When I started down this path I ended up grabbing code from several commerce products written in PHP to see how they did it as I could not get the UPS examples to work. Turns out most of them are just doing a POST and manually assembling the XML instead of using SOAP, since it's so painful.
But, regardless, what it wants in $wsdl is the wsdl file location.
End point url is the UPS url for the service you wish to use, for example, for TimeInTransit:
For prod: https://wwwcie.ups.com/ups.app/xml/TimeInTransit
For test: https://onlinetools.ups.com/ups.app/xml/TimeInTransit
EDIT: It appears that the urls above are incorrect. Reference: https://developerkitcommunity.ups.com/index.php/Special:AWCforum/st/id267
Once your testing is completed please direct your Shipping Package XML to the Production
URL:
https://onlinetools.ups.com/webservices/Ship
They should read:
For test: https://wwwcie.ups.com/ups.app/xml/TimeInTransit
For prod: https://onlinetools.ups.com/ups.app/xml/TimeInTransit