File storage not working using jackrabbit from localhost - php

I have not much idea about PHPCR.I am doing a sample prototype to store the files into a WebDav server.The code snippet is given below.It's only creating the node.But I want the file to be stored in the server.
$jackrabbit_url = 'http://xxxxxxxxxx:8900/jackrabbit/server';
$user = 'xxxxxx';
$pass = 'xxxxxx';
$workspace = 'default';
$factory = new \Jackalope\RepositoryFactoryJackrabbit();
$repository = $factory->getRepository(
array("jackalope.jackrabbit_uri" => $jackrabbit_url)
);
$credentials = new \PHPCR\SimpleCredentials($user, $pass);
$session = $repository->login($credentials, $workspace);
$node = $session->getNode('/test');
$imageURL ='/var/www/sxnew/phpcr/web/uploads/FolderE/test.png';
$contents = base64_encode(file_get_contents($imageURL));
$image = $node->addNode("test.png");
$image->setProperty("jcr:content", "nt:resource");
$image->setProperty("jcr:data", $contents);
$image->setProperty("jcr:mimeType", "image/png");
$session->save();
Please help anybody

Related

PHP Google Api Client SQL Admin not enable Auth IP

I have this code that updates my Google MySQL instance authorized IPs, connection is ok, the code prints me the current IP's but it cannot add a new IP to the settings I tried many ways but it still do not works it doesn't make any change to the Instance configuration.
$client = new Google_Client();
$client->setAuthConfig('../config/service-account.json');
$client->setApplicationName(env("APP_NAME"));
$projectName = env("GOOGLE_PROJECT_NAME");
$instanceName = env("SQL_INSTANCE_NAME");
$scopes = [
"https://www.googleapis.com/auth/sqlservice.admin",
"https://www.googleapis.com/auth/compute",
];
$client->addScope($scopes);
$sql = new Google_Service_SQLAdmin($client);
$sqlAdmin = new Google_Service_SQLAdmin_Settings($client);
$instanceSettings = $sql->instances->get($projectName, $instanceName)->getSettings();
$authNetworks = $instanceSettings->getIpConfiguration();
$newAuthNetwork = new Google_Service_SQLAdmin_AclEntry($client);
$newAuthNetwork->setName("tmp_ip_connection");
$newAuthNetwork->setKind("sql#aclEntry");
$authNetworks->setAuthorizedNetworks($newAuthNetwork);
$ipv4 = file_get_contents('https://api.ipify.org');
$newAuthNetwork->setValue($ipv4);
$ipConfiguration = new Google_Service_SQLAdmin_IpConfiguration($client);
$ipConfiguration->setIpv4Enabled(true);
$ipConfiguration->setAuthorizedNetworks([$newAuthNetwork]);
$instanceSettings->setIpConfiguration($ipConfiguration);
$sql->instances->get($projectName, $instanceName)->setSettings($instanceSettings);
//TODO why it is not working??
print_r($sql->instances->get($projectName, $instanceName)->getSettings()->getIpConfiguration()->getAuthorizedNetworks());
The main thing missing from yours is you never updated the instance after you made the change.
Working example:
$client = new Google_Client();
$client->setAuthConfig('../config/service-account.json');
$client->setApplicationName(env("APP_NAME"));
$projectName = env("GOOGLE_PROJECT_NAME");
$instanceName = env("SQL_INSTANCE_NAME");
$scopes = [
"https://www.googleapis.com/auth/sqlservice.admin",
"https://www.googleapis.com/auth/compute",
];
$client->addScope($scopes);
$sql = new Google_Service_SQLAdmin($client);
$instances = $sql->instances;
$instance = $instances->get('projectId', 'instanceId');
$networks = $instance->getSettings()->getIpConfiguration()->getAuthorizedNetworks();
$values = [];
foreach ($networks as $network) {
$values[$network->getName()] = $network;
}
$values['1.production'] = array_get($values, '1.production', clone head($values));
$external_ip = #file_get_contents('http://ipecho.net/plain');
$values['1.production']->setValue("$external_ip/32");
$values['1.production']->setName('1.production');
$instance->getSettings()->getIpConfiguration()->setAuthorizedNetworks(array_values($values));
$instances->update('projectId', 'instanceId', $instance);

Why do I get NULL response when I request AuthToken?

I'm building bigcommerce APP. But I cannot get "AuthToken". Please help. See full code below. Also attached image with NULL response.
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php');
use Bigcommerce\Api\Client as Bigcommerce;
$object = new \stdClass();
$object->client_id = BC_CLIENT_ID;
$object->client_secret = BC_CLIENT_SECRET;
$object->redirect_uri = 'https://yourwebsiteurl.com/oauth.php';
$object->code = $_GET['code'];
$object->context = $_GET['context'];
$object->scope = $_GET['scope'];
$authTokenResponse = Bigcommerce::getAuthToken($object);

Google Cloud DNS Services - entity.change parameter is required but missing

With the following code using Google's PHP API Client I am receiving this response.
Google_Service_Exception with message 'Error calling POST https://www.googleapis.com/dns/v1/projects/PROJECT-NAME/managedZones/DNSZONE/changes: (400) The 'entity.change' parameter is required but was missing.
Where PROJECT-NAME and DNSZONE are my project and zone.
$client_email = MYCLIENT;
$private_key = file_get_contents('config/credentials/KEY.p12');
$scopes = array('https://www.googleapis.com/auth/ndev.clouddns.readwrite');
$project = "PROJECT-NAME";
$managedZone = "DNSZONE";
$creds = new Google_Auth_AssertionCredentials($client_email,$scopes,$private_key);
$client = new Google_Client();
$client->setAssertionCredentials($creds);
$resource = new Google_Service_Dns_ResourceRecordSet();
$resource->kind = "dns#resourceRecordSet";
$resource->name = "testing.DNSZONE.net.";
$resource->rrdatas[] = "testing.otherhost.com.";
$resource->ttl = 800;
$resource->type = "CNAME";
$dns = new Google_Service_Dns($client);
$change = new Google_Service_Dns_Change();
$change->kind = "dns#change";
$change->setAdditions($resource);
$dns->changes->create($project,$managedZone,$change);
I am a bit confused as to how to set this parameter. Or where I am even am to define it.
Just for clarify what the answer is, setAdditions expects an array.
$change->setAdditions([ $resource ]);

Twitter access to resource error after first connection

I successfully setup twitteroauth and posted a message. Now, when I try to post again, and every time AFTER THE FIRST successful message post, I get an error Your credentials do not allow access to this resource. (code 220);
Here's my code:';
$message = 'Test';
$apiKey = Ranger_Application_Util::getConfig('twitter_app_api_key');
$apiSecret = Ranger_Application_Util::getConfig('twitter_app_api_secret');
$consumerToken = Ranger_Application_Util::getStorageData('twitter_oauth_token');
$consumerSecret = Ranger_Application_Util::getStorageData('twitter_oauth_secret');
$twitterOauthVerifier = Ranger_Application_Util::getStorageData('twitter_oauth_verifier');
$_SESSIOM['oauth_token'] = $consumerToken;
$_SESSION['oauth_token_secret'] = $consumerSecret;
require_once 'twitter/twitteroauth.php';
$connection = new TwitterOAuth($apiKey,$apiSecret,$consumerToken,$consumerSecret);
$connection->host = "https://api.twitter.com/1.1/";
$accessToken = $connection->getAccessToken($twitterOauthVerifier);
$_SESSION['access_token'] = $accessToken;
$parameters = array('status' => $message);
$status = $connection->post('statuses/update',$parameters);
Core::dump($status);
die();
The data I retrieve from getStorageData is values stored in the database that pertain to that specific user.
Unless you are storing the information from $accessToken to your database in a piece of code you have not posted, I believe the issue may be that you are getting the access token after your initial connection, but not using the permanent access information from the access token when trying to post to the connection. So any future requests will not be using the permanent credentials and are therefore rejected. Try something like this:
$message = 'Test';
$apiKey = Ranger_Application_Util::getConfig('twitter_app_api_key');
$apiSecret = Ranger_Application_Util::getConfig('twitter_app_api_secret');
$twitterOauthVerifier = Ranger_Application_Util::getStorageData('twitter_oauth_verifier');
require_once 'twitter/twitteroauth.php';
$hasAccessToken = (
array_key_exists('oauth_token', $_SESSION) &&
array_key_exists('oauth_token_secret', $_SESSION));
if ($hasAccessToken)
{
$consumerToken = $_SESSION['oauth_token'];
$consumerSecret = $_SESSION['oauth_token_secret'];
}
else
{
$consumerToken = Ranger_Application_Util::getStorageData('twitter_oauth_token');
$consumerSecret = Ranger_Application_Util::getStorageData('twitter_oauth_secret');
$connection = new TwitterOAuth($apiKey, $apiSecret, $consumerToken, $consumerSecret);
$connection->host = "https://api.twitter.com/1.1/";
$accessToken = $connection->getAccessToken($twitterOauthVerifier);
$consumerToken = $accessToken['oauth_token'];
$consumerSecret = $accessToken['oauth_token_secret'];
$_SESSION['oauth_token'] = $consumerToken;
$_SESSION['oauth_token_secret'] = $consumerSecret;
}
$connection = new TwitterOAuth($apiKey, $apiSecret, $consumerToken, $consumerSecret);
$connection->host = "https://api.twitter.com/1.1/";
$parameters = array('status' => $message);
$status = $connection->post('statuses/update', $parameters);
Core::dump($status);
die();
You may want to store the oauth token information in your database after receiving it from getAccessToken() rather than using sessions. Maybe you have a method like Ranger_Application_Util::setStorageData('twitter_oauth_token', $consumerToken)?
This
$_SESSIOM['oauth_token'] = $consumerToken;
^
should be
$_SESSION['oauth_token'] = $consumerToken;

Uploading video to youtube using api's through php

$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = '****#gmail.com',
$password = '*****',
$service = 'youtube',
$client = null,
$source = 'testphp',
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
I have got the above code from code.google.com. I want to know what authenticationURL should be. I new to this help me out
If you copied your code from here, then you missed this line:
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
That's what it is.

Categories