I am new to Secret manager and I am trying to display a test secret using a php app.
All I get when the app is deployed is an error 500.
I gave my xxxx#appspot.gserviceaccount.com service account the required role according to gcp documentation (Secret Manager Secret Accessor + Storage Object Admin)
I also installed composer from the cloud shell so I really cannnot spot what I am doing the wrong way.
This is my composer.json
{
"require-dev": {
"paragonie/random_compat": "^9.0.0"
},
"require": {
"google/cloud-secret-manager": "^1.2"
}
}
this is how my code looks like:
<?php
use Google\Cloud\SecretManager\V1\SecretManagerServiceClient;
$projectId = 'myproject';
$secretId = 'mysecret';
$versionId = '1';
$client = new SecretManagerServiceClient();
$name = $client->secretVersionName($projectId, $secretId, $versionId);
$response = $client->accessSecretVersion($name);
$payload = $response->getPayload()->getData();
printf('Plaintext: %s', $payload);
?>
Thank you for your help...I don't know what to try anymore :-(
Ok, so I managed to make this work. As a typical noob I made a lot of nonsense ^^ so long story short:
First I have (had?) a bad habit to build my app from the google shell (not sdk). Nothing wrong with that I guess (except it is actually less convenient) but in this usecase you need to link a json file containing access key to your GOOGLE_APPLICATION_CREDENTIALS environnment variable so it will have the right to query secret manager.I did not know how to do that without the sdk. So once the app deployed using the sdk and the json file properly assigned, it was better. Then I had an autoload.php error I managed to fix using this article in french : https://www.journaldunet.fr/web-tech/developpement/1441107-comment-corriger-l-erreur-require-vendor-autoload-php-failed-to-open-stream/
Thank you guys for trying to help me. I learnt one or two interresting things with this issue....Everyday is a school day ^^
Related
I have code which works above the php 5
its actually GA Library, here is its github project.
I have cloned the project theiconic/php-ga-measurement-protocol
Since I am new to PHP, I have no idea where to put this code, Please help me here this project should be installed via composer via code
{
"require": {
"theiconic/php-ga-measurement-protocol": "^2.0"
}
}
After this step I need to create a file something.php and I need to put the code below, I am having problem on locating autoload.php on my server, Please look at the code below to understand what i am saying.
<?php
//grab the data that Calendly sent in the webhook and store it in a variable called $objCalendlySubmission...
$objCalendlySubmission = json_decode(file_get_contents('php://input'));
//We've passed the Google client_id in Calendly's placeholder for utm_term. Feel free to pass it differently, this is just an example
if(property_exists($objCalendlySubmission->payload->tracking, 'utm_term') && !empty($objCalendlySubmission->payload->tracking->utm_term)) {
$strPageViewed = 'calendly_conversion.html'; // We use different page names depending on what type of event was scheduled via Calendly
sendGoogleAnalyticsPageView($objCalendlySubmission->payload->tracking->utm_term, $strPageViewed);
}
function sendGoogleAnalyticsPageView($strGAClientId, $strURL) {
require_once '/path_to_composer/composer/vendor/autoload.php'; //loads the PHP library for the "Google Analytics Measurement Protocol” **I dont know where is it located exactly on my xampp server, Please guide me here**
$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true); //you may have to adjust this path based on your setup **please help me here**
$analytics
->setProtocolVersion('1')
->setTrackingId('YOUR-GA-UA-ID-GOES-HERE')
->setClientId($strGAClientId)
->setDocumentLocationUrl($strURL);
$analytics->sendPageview();
}
?>
In the above code towards middle line
require_once '/path_to_composer/composer/vendor/autoload.php'; //loads the PHP library for the "Google Analytics Measurement Protocol”
I dont know where is it located exactly on my xampp server, Please guide me here
$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true); //you may have to adjust this path based on your setup
Here is the image of Project folder
Project structure Part 2
I need your advice. I made API in php to communicate with my android application and mySQL database. Now I wanna put this api on free online hosting with free database, the problem is that when i make query for that API I'm receiving my json data with junk from hosting like HTML tags and commercial text "[hosting name] free hosting". When my app receives this data, it shuts down. Everything works fine on local wamp server but at online hosting my app is crashing
I have 3 questions for you
Is it normal on free hosting or maybe my API is wrong designed?
If I put my php files on paid serwer will I avoid this additional stuff added by hosting company?.
Check out part of my sample user registration php code
$new_sql_select_query = "select * from userinfo where userName like '$userName' and userEmail like '$userEmail';";
$sql_all_data = mysqli_query($con, $new_sql_select_query);
$userDataJson = array();
while ($row = mysqli_fetch_array($sql_all_data)) {
$userDataJson["userId"] = $row["userId"];
$userDataJson["userName"] = $row["userName"];
$userDataJson["userEmail"] = $row["userEmail"];
$userDataJson["accountBalance"] = $row["accountBalance"];
}
$responseJson["success"] = 1;
$responseJson["message"] = "User correctly added to base!";
array_push($responseJson["user"], $userDataJson);
echo json_encode($responseJson);
I have an idea but I do not know how to do it correctly. I am generating a new json data file by code below
$myjson = json_encode($responseJson);
file_put_contents('myfile.json', $myjson);
but here is another problem, my app need to be somehow redirected to this new file because right now my app is connecting directly to a specific php file in this case CreateNewUserDB.php so how should I do it?. Should I return link to this generated json file to my app and then make another connection but this time to this "myfile.json" file?. Waiting for answers.
Regards
The reason that your app might be crashing is that when you do send response to your app on localhost, then only json data is sent. But as you said on the free hosting, you got some html. When your java code tried to make a json object out of it, it must have thrown an exception and hence the error.
There are plenty of free hosting, that are good and don't do these type of advertisements. https://www.biz.nf/ is one of them. I used it in my early years. Also paid hosting will not give you problems like these
This is an old thread, but I had a similar problem recently.
I uploaded my php json api in my shared hosting and solved the problem setting the right format by adding the header for json in the php file:
header('Content-Type: application/json');
I encourage you to work with Firebase, it will handle all the background staff for you, and it gives you access to the database also, besides that, it's very fast comparing to regular databases.
I'm using OctoberCMS based on Laravel freamwork.
I would like to have option on my website "sign in with google account".
So I went to https://developers.google.com/identity/sign-in/web/devconsole-project
and I fallowed all of the steps to "Authenticate with a backend server".
Becouse I don't have ssh access to my domain ( I cannot install library using Composer), so I downloaded Google API Client Library for php in .zip .
I unpacked it to 'plugins/nameOfMyplugin/google'.
And I got stuck,becouse I don't have any idea how to Send the ID token to my server and to validate it with those library, then I would like to create new user in my db if not exist in my rainlab.user.plugin.
Thank You for any help.
I have solved it.
In octoberCMS there is no reason for connect with google api by Your own, better solusion is download already made plugin(octobercms.com/plugin/flynsarmy-sociallogin) which is working.
I just downloaded octobercms.com/plugin/flynsarmy-sociallogin, but as I said it before, got some problems with login into my website.
I sow that each 12 minutes break between log out and log into my website I can login. When I tried to log into after in 11 minutes after log out it didn't work.
I went to my backend/ settings / logs /event logs and sow that
Cannot handle token prior to 2017-04-19T08:27:14+0000 in public_html/plugins/flynsarmy/sociallogin/vendor/firebase/php-jwt/src/JWT.php on line 124.
It's mean that my server time have 12 minutes late.
There are 2 ways to solve it:
First one not good for safety reasons:
SET in plugins/flynsarmy/sociallogin/vendor/firebase/php-jwt/src/JWT.php
public static $leeway = x;
Where x are secunds, in my example
or add difference of time in this if in from 123 :
if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway +
**720**)) {
throw new BeforeValidException('Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat)
);
}
But as I said... it's not safety...
Second solution is to set time on server in right way.
There is a lot of solutions how to do it:
http://www.inmotionhosting.com/support/website/php/update-local-php-settings
https://help.directadmin.com/item.php?id=52
http://forum.directadmin.com/showthread.php?t=1817
I'm trying to use the Tumblr API (PHP) and I cant seem to get all the required files to load correctly.
The Tumblr API can be found here: https://github.com/tumblr/tumblr.php
First thing I found out is that it doesnt include OAuth, so after some searching I found the files on github and uploaded them to my server.
Now it's saying it needs Guzzle. OK, got that uploaded now, but I cant seem to get all the Guzzle files to load up... Example error message:
Interface 'Guzzle\Common\HasDispatcherInterface' not found in /TumblrTest/Guzzle/Common/AbstractHasDispatcher.php
There's a HasDispatcherInterface.php file in that path...
Do the files need to be in a special order? I tried putting all .php files into a folder, and then using require_once I searched for all *.php files in that folder, but that didnt work...
Sorry for a super noob question, any help would be greatly appriciated! Let me know if there's any other info i need to give to help answer this question!
-D
UPDATE: I still have no idea how the above works, but I found a way around it... I actually think it might be easier then figuring the above out!! The following PHP code does what i need it to do, which is grab the posts of the provided user:
$apikey = **[insert api key here]**;
$limit = $_POST['limit'];
$user = $_POST['user'];
$tumblr=$user . ".tumblr.com";
$apidata = json_decode(file_get_contents("http://api.tumblr.com/v2/blog/$tumblr/posts/photo?api_key=$apikey&limit=$limit"));
$mypostsdata = $apidata->response->posts;
$myposts = array();
$j = 0;
foreach($mypostsdata as $postdata) {
$post["photo_url"] = $postdata->photos[0]->original_size->url;
$post["width"] = $postdata->photos[0]->original_size->width;
$post["height"] = $postdata->photos[0]->original_size->height;
$myposts[$j] = $post;
$j++;
}
echo json_encode($myposts);
For some reason I cant get it to pull a list of people i'm following and then get their posts, but oh well...
The tumblr.php Readme might be a bit confusing.
The package depends on other packages. All can be installed via composer.
Go to the http://getcomposer.org and read this carfully, if you are used to the concept, you will start rewriting all you classes to fit the composer dependency manager ;-)
to make it short:
install composer globally and
go into a blank directory and
type in your terminal
composer require tumblr/tumblr
you should get all the classes and the other projects in a dir called vendor.
before you do anything you need to require the autoload.php file.
And check out the concept of namespaces in php.
Howdy. I've been tasked with making a Facebook game, but I'm new to Facebook development, so I'm just getting started. Apologies in advance if this is a no-brainer to people.
I'm having trouble following all the examples I see on sites, and I keep running into missing pages in the Facebook documentation when I am trying to read up. I think it's because there's a new version of the PHP Client Library for Facebook, and everything I'm finding is referring to the old client.
For instance, I see this code in a lot of examples:
require 'facebook.php';
$facebook = new Facebook( array( 'appId' => '(id)', 'secret' => '(secret)' ) );
$facebook_account = $facebook->require_login();
...but there's no "require_login()" in the client library provided in the facebook.php file.
From what I can tell, it looks like Facebook has very recently rolled out some new system for development, but I don't see any sample code anywhere to deal with it. The new library comes with an "example.php" file, but it appears to be only for adding "Log in with Facebook" functionality to other sites (what I'm assuming is what they mean by "Facebook Connect" sites), not for just running apps in a Canvas page on Facebook itself.
Specifically, what I need to do is let users visit an application page within Facebook, have it bring up the dialog box allowing them to authorize the app, have it show up in their "games" page, and then have it pass me the relevant info about the user so I can start creating the game. But I can't seem to find any tutorials or examples that show how to do this using the new library. Seems like this should be pretty straightforward, but I'm running into roadblocks.
Or am I missing something about the PHP client library? Should require_login() be working for me, and there's something broken with my implementation, such as having the wrong client library or something? I downloaded from GitHub yesterday, so I'm pretty sure I have the most recent version of the code I have, but perhaps I'm downloading the wrong "facebook.php" file...?
The following is a rewrite of the old require_login function. It exactly duplicates the old functionality.
function facebook_require_login($required_permissions = '')
{
global $facebook; // NOTE GLOBAL FACEBOOK OBJECT, MUST ALREADY BE INSTANTIATED
$user = $facebook->get_loggedin_user();
$has_permissions = true;
if ($required_permissions) {
$facebook->require_frame();
$permissions = array_map('trim', explode(',', $required_permissions));
foreach ($permissions as $permission) {
if (!in_array($permission, $facebook->ext_perms)) {
$has_permissions = false;
break;
}
}
}
if ($user && $has_permissions) return $user;
$facebook->redirect(
$facebook->get_login_url(Facebook::current_url(), $facebook->in_frame(),
$required_permissions));
}
phpfour solution is the only correct one - since it utilizes the new php-sdk library from github.
The best solution is to edit the new facebook.php and add a require_login() function (so all existing pages who rely on it can stay the same)
public function require_login(){
if ( !$this->getSession() ) {
$url = $this->getLoginUrl( array(
'canvas' => 1,
'fbconnect' => 0
));
echo "<script type='text/javascript'>top.location.href = '$url';</script>";
}
else
return $this->getUser();
}
The new php script on git hub is a wraper for facebooks api, graph I presume but I've seen code for fql too so who knows. The forums are currently down and IRC was dead when I went across. I have been looking for the same solution as your require authorisation to call ->api(\me). Since the script extends another class if I remember right, you could try using the reflection class/function to see what methods are available. Hopefully some solid documentation is on its way! Please let me know if you solve this. (Sorry for poor formatting I'm on my mobile)
Well, I have been able to find a solution to the problem of authorizing application using the new PHP SDK. You can check my blog post here.
In short, you will need to get an authenticated session and then you can call the functions to get the logged in user's ID. In this case, you will call the "/me" path from the Graph API.