How to download a github json - json

I have a problem, I would try to download all the json generated by this url
https://api.github.com/repos/xxxx/xxxx/contents/xxxxxxx?ref=master
I have a json result like that
[
{
"name": "xxxx.png",
"path": "xxxx/xxxx.png",
"sha": "8b33da362caab310626daa2b70b232a98b38c6db",
"size": 136356,
"url": "https://api.github.com/repos/xxxx/xxxx/contents/xxxx/xxxx.png?ref=master",
"html_url": "https://github.com/xxxx/xxxx/blob/master/xxxx/xxxx.png",
"git_url": "https://api.github.com/repos/xxxx/xxxx/git/blobs/8b33da362caab310626daa2b70b232a98b38c6db",
"download_url": "https://raw.githubusercontent.com/xxxx/xxxx/master/ModuleInfosJson/xxxx.png",
"type": "file",
"_links": {
"self": "https://api.github.com/repos/xxxx/xxxx/contents/xxxx/xxxx.png?ref=master",
"git": "https://api.github.com/repos/xxxx/xxxx/git/blobs/8b33da362caab310626daa2b70b232a98b38c6db",
"html": "https://github.com/xxxx/module_apxxxx/blob/master/xxxx/xxxx.png"
}
}
]
I write this but it does'nt work and I have this message : failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
Warning: fopen([{"name":"xxxxxx.png","path":"xxxxxx/xxxxxxx.png","sha":"..............
My directory is in 777.
$json = #file_get_contents($this->GetGithubRepo() . '/' . $module_name . '/contents/' . $this->ModuleInfosJson . '?ref=master', true, $this->context );
file_put_contents(OSCOM::getConfig('dir_root', 'Shop') . $this->ModuleInfosJson . '/Cache/' . $module_name . '.json', fopen($json, 'r'));
but if I write the code like that, it's ok but I need the information like sha, git ..., That's I need, not in this case.
$download = 'https://raw.githubusercontent.com/ClicShoppingAddsOn/' . $module_name . '/master/' . $this->ModuleInfosJson . '/' . $module_name . '.json';
file_put_contents(OSCOM::getConfig('dir_root', 'Shop') . $this->ModuleInfosJson . '/Cache/' . $module_name . '.json', fopen($download, 'r'));
Thank you.

I found a solution
$local_file = OSCOM::getConfig('dir_root', 'Shop') . $this->ModuleInfosJson . '/Cache/' . $module_name . '.json';
$remote_file = $this->GetGithubRepo() . '/' . $module_name . '/contents/' . $this->ModuleInfosJson . '?ref=master';
$ch = curl_init();
$fp = fopen ($local_file, 'w+');
$ch = curl_init($remote_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_exec($ch);
curl_close($ch);
fclose($fp);

Related

How can I get registered information to my email [duplicate]

This question already has answers here:
PHP create Excel spreadsheet and then email it as an attachment
(3 answers)
Closed 3 years ago.
I have a landing page, I want to get the registered information straight to my email or get it in some excel file
// send data to some get post API , if so uncomment next code and customize for your needs
$myvars = 'publicid=' . $publicid . '&firstname=' . $firstname . '&lastname=' . $lastname . '&email=' . $email . '&phone=' . $phone . '&country=' . $selected_country . '&leadsource=' . $leadsource[0] . '&ip=' . $ip;
$url = "#";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
var_dump($response);
echo '{"success":true,"message":{"message":"lead insert"}}';
?>
So you want do 2 things, which was already asked in stackoverflow, please read this 2 pages :
Generate an excel with your data :
PHP create Excel spreadsheet and then email it as an attachment
Send an email with attachment:
send email with attachment using php

Yii2 failed passing Image from PHP into Exported Excel, it passing the PHP Script into Excel

I'm trying to insert image from Yii2 into exported Excel;
This is the code :
<?php
$logo = Html::img("#web/img/Logo.jpg", ['width' => '60px', 'height' => '50px', 'margin-top' => '-10px']);
$downloadedTime = $downloadTZ->format('Y-m-d');
$bulan = \Yii::t('app', $month);
$filename = 'Report'.'xls';
header("Content-Disposition: attachment; filename=\"" . $filename . "\"");
header("Pragma: no-cache");
header("Expires: 0");
header("Content-Type: application/force-download");
header("refresh:0;url=../master/index");
echo $logo;
echo "Name\t";
echo "Class\t";
echo "Age\t";
echo "\r\n";
?>
if I echo $logo; the printed in browser, but in Excel it will print the code not the image, just like this
Why does this happen? and How do I can solve this?
Thanks
I do that with PHPExcel class and then calling PHPExcel_Worksheet_Drawing;
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath('img/logo.png');
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
like this.

Tally XML Integration...export employee information from tally

Can anyone suggest what is the structure of xml to exporting employee details from tally.
<?php
/*
PHP Code to Export Employee Master data from Tally ERP 9
Task : Export Exmployee masters from Tally
*/
ini_set('display_errors', 1);
$data =
"<ENVELOPE>" .
"<HEADER>" .
"<TALLYREQUEST>Export Data</TALLYREQUEST>" .
"</HEADER>" .
"<BODY>" .
"<EXPORTDATA>" .
"<REQUESTDESC>" .
"<REPORTNAME>List of Accounts</REPORTNAME>" .
"<STATICVARIABLES>" .
"<SVEXPORTFORMAT>\$\$SysName:XML</SVEXPORTFORMAT>" .
"<ACCOUNTTYPE>Employees</ACCOUNTTYPE>" .
"<!--Other possible values for ACCOUNTTYPE tag are given below-->" .
"<!--All Acctg. Masters, All Inventory Masters,All Statutory Masters-->" .
"<!--Ledgers,Groups,Cost Categories,Cost Centres-->" .
"<!--Units,Godowns,Stock Items,Stock Groups,Stock Categories-->" .
"<!--Voucher types,Currencies,Employees,Budgets & Scenarios-->" .
"</STATICVARIABLES>" .
"</REQUESTDESC>" .
"</EXPORTDATA>" .
"</BODY>" .
"</ENVELOPE>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:9000/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data ); //$data = "XML data"
$response = curl_exec ($ch);
if(curl_errno($ch)){
echo curl_error($ch);
}
else{
print "<pre lang='xml'>" . htmlspecialchars($response) . "</pre>";
curl_close($ch);
}
return "";
?>
Note:
You can get more information about Tally XML tags from here:
Export data from Tally
https://www.rtslink.com/articles/tally-xml-tags-export/
Import data into Tally
https://www.rtslink.com/articles/tally-xml-tags-import/

json_decode doesn't work with string

With this code :
$url = 'https://www.xxxxxxx.com/api/v1/phone/?apikey=xxxxxxxxxx&id='.$id;
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($cURL);
curl_close($cURL);
echo $result;
var_dump ($result);
var_dump(json_decode($result, true));
I get that :
{"telephone":"0 811 228 338"}
string(32) "{"telephone":"X XXX XXX XXX"}"
NULL
I don't understand why json_decode doesn't work here?
Thanks for helping me
with the little info i got i believe its a json formating problem.
<?php
$json = '{"foo-bar": 12345}';
$obj = json_decode($json);
print $obj->{'foo-bar'}; // 12345
?>
the json quotes are not valid
http://php.net/manual/en/function.json-decode.php
try it in some validator as this one http://jsonlint.com/
The solution was that the response is in UTF-8 but not UTF-8 (SANS BOM).
It means that there is a invisible caractere on the beginning of the string (U+FEFF).
The solution : $result = substr($result, 3);
Thanks for your help

Invalid credentials using PHP with the Google apps reseller api

I'm trying to build a couple of webpages to gather info about our GApps customers.
I have all the code needed to get an Oauth token and it even seems to work (at least i can read all my calendar events using the calendar API). When i try to access the reseller api i get so far that i get the token but if i try to access the userinfo,
passing the access_token parameter i get an Invalid Credentials error.
Unfortunately I haven't found much usable documentation on PHP but after all the auth procedure i'm trying to get the data via CURL...
Any ideas what's wrong or what i should do differently?
Still stuck so i thought i'd add the code i'm running now:
<?php
require_once '../google-api-php-client/src/Google_Client.php';
require_once '../google-api-php-client/src/contrib/Google_Oauth2Service.php';
require_once '../google-api-php-client/src/contrib/Google_ResellerService.php';
session_name('reseller');
session_start();
$debug=1;
$clientId='******.apps.googleusercontent.com';
$clientSecret='******';
$redirectURI='*****'; //links to the directory wehere the script is
$key='********';
$scopes='https://www.googleapis.com/auth/apps.order.readonly';
n
$client = new Google_Client();
$client->setApplicationName("Google Reseller PHP Starter Application");
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setRedirectUri($redirectURI);
$client->setDeveloperKey($key);
$client->setScopes($scopes);
if (isset($_GET['code'])) {
if($debug) echo "we have a code! <br />";
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
//echo $_SESSION['token']."<br/>";
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
exit();
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
echo "access token settato<br/>";
}
if ($client->getAccessToken()) {
$mytoken=json_decode($_SESSION['token'], true);
echo "DEBUG SESSION token:".$_SESSION['token']."<br />";
echo "DEBUG token: ".$mytoken['access_token']."<br />";
$domain='******'; //mydomain
//key id defiend above
$fields=array('customerId');
$url="https://www.googleapis.com/oauth2/v1/userinfo/?access_token=".$mytoken['access_token'];
echo $url."<br />";
$ch = curl_init($url);
$scopes&state=antani&access_type=online&approval_prompt=auto");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer: '.$mytoken['access_token'],
));
curl_setopt($ch, CURLOPT_REFERER, "*******"); //server URL
$data = curl_exec($ch);
curl_close($ch);
$resellerService = new Google_ResellerService($client);
if ($debug){
echo "<pre>";
print_r($data);
echo "</pre>";
}
} else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
session_destroy();
?>
Any ideas as to why i still get the "insufficient permissions" error?
thanks!