Missing file in my email when doing resumable upload with gmail api - api

I'd like to have some help because I'm a bit lost right now.
I'm trying to send attachment with my email through resumable upload. But when I check my email in my inbox, I don't see any file. So I've probably forgot something.
Here's my code. So if someone see something ^^
$send_data = 'From: <FROM_EMAIL>' . "\n";
$send_data = 'To: <TO_EMAIL>' . "\n";
$send_data = 'Subject: <SUBJECT>' . "\n";
$send_data = '' . "\n";
$send_data = '<MY MESSAGE>' . "\n";
$send_data= rtrim(strtr(base64_encode($send_data), '+/', '-_'), '=');
$msg = new \Google_Service_Gmail_Mesage();
$msg->setRaw($send_data);
$this->client->setDefer(true);
$request = $this->service->users_messages->send('me', $msg, array('uploadType' => 'resumable'));
$chunkSizeBytes = 1 * 1024 * 1024;
$media = new \Google_Http_MediaFileUpload(
$this->client,
$request,
'message/rfc822',
null,
true,
$chunkSizeBytes
);
$media->setFileSize(filesize(TEST_FILE));
$status = false;
$handle = fopen(TEST_FILE, "rb");
$i = 0;
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
$result = false;
if($status != false) {
$result = $status;
}
fclose($handle);
$this->client->setDefer(false);
Thanks

I don't know much about gmail api, but I feel like setRaw() will need you to compose the full email (include the attachment) instead just of "body".

Related

Image upload type for Graphql magento2

Is there any way to upload image using graphql without using base64 format in magento2
public function uploadFile($fileData)
{
// convert base64 string to image and save as file on server.
$uploadedFileName = "";
$fileName = '';
if (isset($fileData['name'])) {
$fileName = $fileData['name'];
} else {
$fileName = rand() . time();
}
if (isset($fileData['filecontent'])) {
$mediaPath = $this->fileSystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
$originalPath = 'ModuleName/Attachments/';
$mediaFullPath = $mediaPath . $originalPath;
if (!file_exists($mediaFullPath)) {
mkdir($mediaFullPath, 0775, true);
}
/* Check File is exist or not */
$fullFilepath = $mediaFullPath . $fileName;
if ($this->fileDriver->isExists($fullFilepath)) {
$fileName = rand() . time() . $fileName;
}
$fileContent = base64_decode($fileData['filecontent']);
$savedFile = fopen($mediaFullPath . $fileName, "wb");
fwrite($savedFile, $fileContent);
fclose($savedFile);
$uploadedFileName = "/" . $fileName ;
}
return $uploadedFileName;
}
See more: https://magento.stackexchange.com/a/351629/101754

What do I need to do in my PHP file so that my Telegram bot replies to my message in a quote?

I want to make a bot that responds to my message on Telegram.
In fact, the bot I wrote responds to me, but it does not respond by quoting my message.
What do I need to do in my PHP file so that my Telegram bot replies to my message in a quote?
This is my Lowercase Converter Bot's code:
<?php
$website = 'https://api.telegram.org/bot{API}/';
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (isset($update["message"])){
$chatID = $update["message"]["chat"]["id"];
$text = $update["message"]["text"];
if ( $text == '/start' ) {
// send welcome message
file_get_contents($website."sendMessage?chat_id=".$chatID."&text=Send your Text for Converting to Lowercase");
}else{
$text = mb_strtolower($text,"UTF-8");
file_get_contents($website."sendMessage?chat_id=".$chatID."&text=$text");
}
}
?>
You have to specify the reply_to_message_id parameter with the message_id of the message you sent to the bot in the sendMessage request.
<?php
$website = 'https://api.telegram.org/bot{API}/';
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (isset($update["message"])) {
$chatID = $update["message"]["chat"]["id"];
$text = $update["message"]["text"];
$message_id = $update["message"]["message_id"];
if ($text == '/start') {
// send welcome message
file_get_contents($website . "sendMessage?chat_id=" . $chatID . "&text=Send your Text for Converting to Lowercase");
} else {
$text = mb_strtolower($text, "UTF-8");
file_get_contents($website . "sendMessage?chat_id=" . $chatID . "&text=$text&reply_to_message_id=$message_id");
}
}
?>

How to use SHA256 With salt?

I have a hash function on sa-mp
new MyHash[256];
SHA256_PassHash(inputtext, "78sdjs86d2h", MyHash, sizeof(MyHash));
if(!strcmp(MyHash, PlayerInfo[playerid][pKey]))
I assume 78sdjs86d2h is the salt, but how do I set the salt in PHP?
I am using this code, and it hashes but not with my salt.
if(isset($_POST['username']) && isset($_POST['password'])){
mysql_query('SET NAMES utf8');
$var = mysql_real_escape_string("\xbf\x27 OR 1=1 /*");
$username = mysql_real_escape_string($_POST['username']);
$parola = mysql_real_escape_string($_POST['password']);
$hash = hash('sha256', $parola);
$check = get_row("SELECT ID FROM players WHERE Name='$username' && password='$hash' LIMIT 1");
if(isset($check['ID']))
{
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
$id = $check['ID'];
header("location: index.php");
}
else
{
printf("%s", $hash);
$err = 'Username sau parola incorecte';
}
}
How do I make it hash with my own salt?
UPDATE: Tried this way
$username = mysqli_real_escape_string($DB_H, addslashes($_POST['username']));
$password1 = $_POST['password'];
$salt = '78sdjs86d2h';
$parola = hash('sha256', $password1 . $salt);
The result: 33ca067dc70ef75fc1a1107f4345f3a819ecca657d3d9646d26822fd691cd10c
The original: BFD2832240F5FC1FD12004634EBE9FDE97BD0D4690695DFAC1350D0AE037398F

How to get the video upload date with YouTube API V3?

I know how can I get the video duration and views, like that
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=statistics&id=hqepb5hzuB0&key={YOUR-API-KEY}");
$json_data = json_decode($JSON, true);
echo $json_data['items'][0]['statistics']['viewCount'];
But how can I get the video upload date?
$vidkey = "Gsc7_E5HewM" ; //for example
$apikey = "xxxxxxxxxxxxxxxxx" ;
$dur = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=$vidkey&key=$apikey");
//----- duration---
$VidDuration =json_decode($dur, true);
foreach ($VidDuration['items'] as $vidTime)
{
$VidDuration= $vidTime['contentDetails']['duration'];
}
// Check if $VidDuration is ISO string so the video is ready
if (is_string($VidDuration)){
//convert duration from ISO to M:S
$date = new DateTime('2000-01-01');
$date->add(new DateInterval($VidDuration));
$vid_durH= $date->format('H') ;
if ($vid_durH=="00") {
$vid_dur= $date->format('i:s') ;
}
else {
$vid_dur= $date->format('H:i:s') ;
}
}
else {
$vid_dur ="error" ;
}
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$vidkey&key=$apikey");
$json_data = json_decode($JSON, true);
$uploadDate = $json_data['items'][0]['snippet']['publishedAt'];
$uploadDate = strtotime($uploadDate);
$uploadDate= date("F j, Y", $uploadDate);
echo $vid_dur ;

How to grab contacts from gmail using google API's and contact grabber in PHP?

In my project i want to grab the contacts from gmail using google API's. I provide three keys such as client id, client secret and signature key. When i trying to get contacts the pop-up window is showing error message "Signature key must be formatted". What i have done wrong? Thanks in advance.
Here is my code
keyConfig.php
<?php
$apiRequestUrl = "https://stescodes.com/api/contactsapi.aspx"; // StesCodes contact grabber API request url
$originalsignaturekey = "lxFWDA5ng36sdvlFGukof75vyi";//replace with your signature key
$gmailConsumerKey = "1009516162377-n5s7lo5b4dvlt8e7s3rt12f8i02lpk1f.apps.googleusercontent.com";
$gmailConsumerSecret = "raCUba1smsZCzrVNjqFIqiqC";
$YahooConsumerKey = "your yahoo api key";
$YahooConsumerSecret = "your yahoo api key";
$LiveConsumerKey = "your live api key";
$LiveConsumerSecret = "your live api key";
$fbConsumerKey = "your facebook api key";
$fbConsumerSecret = "your facebook api key";
$callbackurl = "http://localhost/grab/oauth.php";// eg: return url after user authentication http://yourdomain/oauth.php
$currentdirpath = "http://dev.stescodes.com/";//your current web directory path eg:http://yourdomain/
?>
oauth.php
<?php
session_start();
?>
<?php include 'keyConfig.php'; ?>
<html>
<head><title></title>
<script>
function redirectrequest(a)
{
window.location = a;
}
function closepopup(a,b,c,d) {
window.opener.startGrabbingContactsOauth(a,b,c,d);
window.self.close();
}
</script>
</head>
<body>
<?php
$servicename = "gmail";
$token = "";
$ConsumerKey = "";
$ConsumerSecret="";
$tokensecret="";
$tokenverifier="";
$flag=0;
$parameters="";
if($_GET['currpage']!=null)
$_SESSION['currpage']=$_GET['currpage'];
if($_SESSION['currpage']=="gmail")
{
$servicename = "gmail";
$ConsumerKey = $gmailConsumerKey;
$ConsumerSecret = $gmailConsumerSecret;
if ($_GET['code'] != null)
{
$token = $_GET['code'];
$tokensecret = $_SESSION['tokensecret'];
$flag = 1;
}
}
else if($_SESSION['currpage']=="yahoo")
{
$servicename = "yahoo";
$ConsumerKey = $YahooConsumerKey;
$ConsumerSecret = $YahooConsumerSecret;
if (($_GET['oauth_token'] != null) && ($_GET['oauth_verifier'] != null))
{
$token = $_GET['oauth_token'];
$tokenverifier = $_GET['oauth_verifier'];
$tokensecret = $_SESSION['tokensecret'];
$flag = 1;
}
}
else if($_SESSION['currpage']=="facebook")
{
$servicename = "facebook";
$ConsumerKey = $fbConsumerKey;
$ConsumerSecret = $fbConsumerSecret;
if (($_GET['code'] != null))
{
$token = $_GET['code'];
$tokenverifier = "";
$tokensecret = "";
$flag = 1;
}
}
else if(($_SESSION['currpage']=="msn") || ($_SESSION['currpage']=="hotmail") || ($_SESSION['currpage']=="msnmessenger"))
{
$servicename = $_SESSION['currpage'];
$ConsumerKey = $LiveConsumerKey;
$ConsumerSecret = $LiveConsumerSecret;
//Live settings
if ($_GET["code"] != null)
{
$token = $_GET["code"];
$flag = 1;
}
}
if ($flag == 1)
{
$parameters = "type=accesstoken&ServiceName=" . urlencode($servicename) . "&ConsumerKey=" . urlencode($ConsumerKey) . "&ConsumerSecret=" . urlencode($ConsumerSecret);
$parameters = $parameters . "&ReturnUrl=" . urlencode($callbackurl) . "&Token=" . urlencode($token) . "&TokenSecret=" . urlencode($tokensecret) . "&TokenVerifier=" . urlencode($tokenverifier);
$result = file_get_contents($apiRequestUrl."?".$parameters);
$authdetails = json_decode($result,true);
$_SESSION['token'] = $authdetails[details][token];
$_SESSION['tokensecret'] = $authdetails[details][tokenSecret];
$_SESSION['uid'] = $authdetails[details][userID];
$_SESSION['tokenverifier'] = $_SESSION['tokenverifier'];
$_SESSION["consumerkey"] = $ConsumerKey;
$_SESSION["consumersecret"] = $ConsumerSecret;
echo "<SCRIPT LANGUAGE=\"javascript\"> closepopup('".$servicename."',". $result .",'".$ConsumerKey."','".$ConsumerSecret."');</SCRIPT>";
}
else
{
$parameters = "type=authenticationurl&ServiceName=" . urlencode($servicename) . "&ConsumerKey=" . urlencode($ConsumerKey) . "&ConsumerSecret=" . urlencode($ConsumerSecret);
$parameters = $parameters . "&ReturnUrl=" . urlencode($callbackurl) ;
$result = file_get_contents($apiRequestUrl."?".$parameters);
$authdetails = json_decode($result,true);
$_SESSION['token'] = $authdetails[details][token];
$_SESSION['tokensecret'] = $authdetails[details][tokenSecret];
$_SESSION['uid'] = $authdetails[details][userID];
$_SESSION['tokenverifier'] = $tokenverifier;
echo "<SCRIPT LANGUAGE=\"javascript\"> redirectrequest('".$authdetails[details][authUrl]."'); </SCRIPT>";
}
?>