I have a success to download a repository from github via file_get_content but what is the orientation with curl.
The advantage with the file_get_content it's like anonymous. In this case inside a backoffice, it's possible to download plugin in for example.
But Github restrict this usage at less 10 times, after the user must to wait long time to restart something.
It seems if the curl is used, github allow more access to download a respository.
Do you have an example to use with curl (like anonymous)?
Below an example that I make. It's works fine but it's not possible to use this several times. Think less 10 times.
Thank you
public function __construct() {
$this->githubUrl = 'https://github.com';
$this->githubApi = 'https://api.github.com';
$this->githubRepo = 'repos';
$this->context = stream_context_create(array('http' => array('header' => 'User-Agent: ClicShopping',)));
$this->githubRepoClicShoppingCore = 'CoreofApplication';
$this->githubRepoName = 'addOnNameOfApplication';
}
private function getGithubRepo() {
$url = $this->githubApi . '/' . $this->githubRepo . '/' . $this->githubRepoName;
return $url;
}
private function getGithubCoreRepo() {
$url = $this->githubApi . '/' . $this->githubRepo . '/' . $this->coreName . '/' . $this->githubRepoClicShoppingCore;
return $url;
}
private function setContext() {
return $this->context;
}
private function getGithubApiClicShoppingCoreArchive() {
$url = $this->githubUrl . '/' .$this->coreName . '/' . $this->githubRepoClicShoppingCore.'/archive/master.zip';
return $url;
}
Thank you.
Related
I have set up some credentials in my google project and a staging app on facebook, using the correct credentials for each and using Hybridauth on my php app I keep getting a "missing redirect_uri parameter" error for facebook and an "invalid grant_type" error for google. Using a different set of credentials for google and facebook both work perfectly on my local set up. Its just when I swap the credentials and upload to staging server that i am getting this issue. Any help would be great thank you.
class HybridAuth {
/**
* #return
*/
public function getUserProfile($platform = 'facebook', $withBooking = false) {
$withBooking = ($withBooking) ? '&withBooking=true' : '';
$config = [ 'callback' => config('app.url.fullyQualifiedDomain') . '/auth/social-login?platform=' . $platform . $withBooking,
'keys' => ['id' => config('vendors.' . $platform . '.keys.appId'),
'secret' => config('vendors.' . $platform . '.keys.appSecret')]];
$hybridauth = $this->$platform($config);
try {
$hybridauth->authenticate();
$isConnected = $hybridauth->isConnected();
if($isConnected){
$userProfile = $hybridauth->getUserProfile();
$hybridauth->disconnect();
return $userProfile;
}
return false;
} catch(\Exception $e) {
trigger_error(get_class($e) . ': ' . $e->getMessage() . '<br /><br />' . $e->getTraceAsString(), E_USER_ERROR);
}
}
private function facebook($config) {
return new \Hybridauth\Provider\Facebook($config);
}
private function google($config) {
return new \Hybridauth\Provider\Google($config);
}
}
I can get data from the Trello API using this:
private function get_card_info($card_id) {
$client = new \GuzzleHttp\Client();
$base = $this->endpoint . $card_id;
$params = "?key=" . $this->api_key . "&token=" . $this->token;
$cardURL = $base . $params;
$membersURL = $base . "/members" . $params;
$attachmentsURL = $base . "/attachments" . $params;
$response = $client->get($cardURL);
$this->card_info['card'] = json_decode($response->getBody()->getContents());
$response = $client->get($membersURL);
$this->card_info['members'] = json_decode($response->getBody()->getContents());
$response = $client->get($attachmentsURL);
$this->card_info['attachments'] = json_decode($response->getBody()->getContents());
}
However, this is broken into three calls. Is there a way to get card information, the member information, and the attachment information all in one call? The docs mention using &fields=name,id, but that only seems to limit what's returned from the base call to the cards endpoint.
It's absurd to have to hit the API 3 times every time I need card information, but I can't find any examples gathering all that's needed.
Try hitting the API with following parameters:
/cards/[id]?fields=name,idList&members=true&member_fields=all&& attachments=true&&attachment_fields=all
Trello replied to me, and stated that they would have answered much like Vladimir did. However, the only response I got from that was the initial card data, sans attachments and members. However, they also directed me to this blog post that covers batching requests. They apparently removed it from the docs because of the confusion it created.
To summarize the changes, you essentially make a call to /batch, and append a urls GET parameter with a comma separated list of endpoints to hit. The working final version ended up looking like this:
private function get_card_info($card_id) {
$client = new \GuzzleHttp\Client();
$params = "&key=" . $this->api_key . "&token=" . $this->token;
$cardURL = "/cards/" . $card_id;
$members = "/cards/" . $card_id . "/members";
$attachmentsURL = "/cards/" . $card_id . "/attachments";
$urls = $this->endpoint . implode(',', [$cardURL, $members, $attachmentsURL]) . $params;
$response = $client->get($urls);
$this->card = json_decode($response->getBody()->getContents(), true);
}
The method i tried using was with openssl
$fp = fopen($key, 'r'); //open the PEM file
$priv_key = fread($fp,8192);
fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key,"password");
openssl_sign($response["data_to_sign"], $signature, $pkeyid,'sha256');
$sign = base64_encode($signature)
Is this the correct Method to generate signature for signed urls in google?
You can try Google Cloud Storage PHP SDK, it's a good choice for keeping your codes clean.
cloud-storage PHP SDK
Install package to your project by following this page
on Packagist,
then
function getSignedGcsUrl($objPath/* which is your target object path */, $duration = 50)
{
$storageClient = new StorageClient([
'projectId' => /* your gcp projectId here */,
'keyFilePath' => /* your gcp keyFilePath here */,
]);
$bucket = $storageClient->bucket($objPath);
$object = $bucket->object();
$url = $object->signedUrl(new \DateTime('+ ' . $duration . ' seconds'));
return $url;
}
laravel-google-cloud-storage (for Laravel)
Install and configurate superbalist/laravel-google-cloud-storage by following this page:
on Github,
then
public static function getSignedGcsUrl($objPath, $duration = 50)
{
return Storage::disk('gcs'/* following your filesystem configuration */)
->getAdapter()
->getBucket()
->object($objPath)
->signedUrl(new \DateTime('+ ' . $duration . ' seconds'));
}
I put all the answers together. This should work in out of the box project. If you have space in the paths, you will need to rawurlencode the individual components, not urlencode.
function signedGoogleStorageURL($bucketName, $resourcePath, $duration = 10, $method = 'GET')
{
$expires = time() + $duration;
$content_type = ($method == 'PUT') ? 'application/x-www-form-
urlencoded' : '';
$to_sign = ($method . "\n" .
/* Content-MD5 */ "\n" .
$content_type . "\n" .
$expires . "\n" .
"/" . $bucketName . $resourcePath);
$sign_result = AppIdentityService::signForApp($to_sign);
$signature = urlencode(base64_encode($sign_result['signature']));
$email = AppIdentityService::getServiceAccountName();
return ('https://storage.googleapis.com/' . $bucketName .
$resourcePath .
'?GoogleAccessId=' . $email .
'&Expires=' . $expires .
'&Signature=' . $signature);
}
$signedPath = signedGoogleStorageURL(AppIdentityService::getDefaultVersionHostname(), "/my_folder/my_file", 60);
One thing to note that I spent about two hours on:
The GoogleAccessId you pass into the URL is the Email Address in the "Certificate" section of the Google Cloud Console. It's not the OAuth Client ID with a string replacement as Google suggests in their documentation.
There's an example here that signs a URL for Google Cloud Storage using PHP:
https://groups.google.com/forum/#!msg/google-api-php-client/jaRYDWdpteQ/xbNTLfDhUggJ
However - I note this is tagged with Google App Engine... If your code is running inside of Google App Engine, you should use the built-in App Identity service - (note this will only work once your application is deployed in production, not while running locally) - this means you will not need to download or handle any private keys:
require_once 'google/appengine/api/app_identity/AppIdentityService.php';
$sign_result = AppIdentityService::signForApp( $message );
You will need to make sure that the service account associated with the App Engine application is added to the team for the project that owns the Cloud Storage bucket.
This is their sample I don't know how to get it working.
http://aws.amazon.com/code/AWIS/402
It keeps showing: Usage: $argv[0] ACCESS_KEY_ID SECRET_ACCESS_KEY site\n
It is not working, when you fill in:
$urlInfo = new UrlInfo("myaccessKeyId", "mysecretAccessKey", "stackoverflow.com");
How do I fix this issue?
public function UrlInfo($accessKeyId, $secretAccessKey, $site) {
$this->accessKeyId = $accessKeyId;
$this->secretAccessKey = $secretAccessKey;
$this->site = $site;
}
/**
* Get site info from AWIS.
*/
public function getUrlInfo() {
$queryParams = $this->buildQueryParams();
$sig = $this->generateSignature($queryParams);
$url = 'http://' . self::$ServiceHost . '/?' . $queryParams .
'&Signature=' . $sig;
$ret = self::makeRequest($url);
echo "\nResults for " . $this->site .":\n\n";
self::parseResponse($ret);
}
The script is meant to be run from the command line like so:
php urlinfo.php ACCESS_KEY_ID SECRET_ACCESS_KEY site
It's in the readme. If you just want to use the class, you should take out the stuff after line 122 in the php file.
I am using Cloud File API of Rackspace Cloud server in PHP, I want to generate a temp url to download files for direct to my server for this i am using get_temp() method of this api but before use to this method i have to set Meta Data key for my container. How would i do this.
public function get_temp_url($key, $expires, $method)
{
$expires += time();
$url = $this->container->cfs_http->getStorageUrl() . '/' . $this->container->name . '/' . $this->name;
return $url . '?temp_url_sig=' . hash_hmac('sha1', strtoupper($method) .
"\n" . $expires . "\n" . parse_url($url, PHP_URL_PATH), $key) .
'&temp_url_expires=' . $expires;
}
The comments on this page include an example of how to set this:
http://docs.rackspace.com/files/api/v1/cf-devguide/content/Set_Account_Metadata-d1a4460.html
Also, if you use the new Cloud Files API...
https://github.com/rackspace/php-opencloud
...it includes a SetTempUrlSecret method in the ObjectStore class that will do this for you.