I'm messing around with writing a own bot for telegramm using hook.io to host the php script. The problem that I have is that file_get_contents("php://input") always seems to be empty, since the bot does not react if I try to do anything related to the update:
$updates = json_decode(file_get_contents('php://input') ,true);
if($updates['ok']){
//loop over all messages
foreach($updates['result'] as $key => $value){
if($value['message']['text']==="/test"){
$chat_id = $value['message']['chat']['id'];
$result = file_get_contents( $apiURL . $apiToken . '/sendMessage?chat_id=' . $chat_id . '&text=test');
}
}
}
Can anyone tell whats wrong with this one?
I corrected in this way:
$updates = json_decode(file_get_contents('php://input') ,true);
if($updates['update_id']){
if($updates['message']['text']==="/test"){
$chat_id = $updates['message']['chat']['id'];
$result = file_get_contents( $apiURL . $apiToken . '/sendMessage?chat_id=' . $chat_id . '&text=test');
}
}
the message is always one, so I deleted the foreach
Related
when i use sendMessage() method to send message in chat when i am using telegram bot in group automatically reply last message
how can i solve this?
[enter image description here][1]
function Start($obj_tblTemp, $Token) {
$Keyboard = array(
'keyboard' => array(
array(INSERT_EXPENSE, DELETE_EXPENSE),
array(EXPENSE_SITUATION, RULES_AND_HELP),
array(CANCEL)
)
);
$Key_board = json_encode($Keyboard);
$url = 'https://api.telegram.org/bot' . $Token . '/sendMessage?text='. $obj_tblTemp->get_message() . '&chat_id=' . $obj_tblTemp->get_chat_Id() . '&reply_markup=' . $Key_board;
file_get_contents($url);
}
also above problem exist in below function:
function InsertExpenseMode($obj_tblTemp, $Token, $con, $obj_tblTempLatestSession) {
if ($obj_tblTemp->get_message() == INSERT_EXPENSE) {
$url = 'https://api.telegram.org/bot' . $Token . '/sendMessage?text='
. INSERT_EXPENSE_INSTRUCTION . '&chat_id=' . $obj_tblTemp->get_chat_Id();
file_get_contents($url);
} else {
if (is_numeric($obj_tblTemp->get_message()) && $obj_tblTemp->get_message() > 0) {
$url = 'https://api.telegram.org/bot' . $Token . '/sendMessage?text='
. $obj_tblTemp->get_message() . '&chat_id=' . $obj_tblTemp->get_chat_Id();
file_get_contents($url);
} else {
$url = 'https://api.telegram.org/bot' . $Token . '/sendMessage?text='
. NUMERAL_FAIL . '&chat_id=' . $obj_tblTemp->get_chat_Id();
file_get_contents($url);
}
}
}
actually i send class objects to these function and want to evaluate user inputs then insert them to database, but development wasn't completed yet.
I want to transfer bitcoin through bitcoin address in PHP please share the proper link.
https://developers.coinbase.com/docs/merchants/payment-buttons
Try This code for transfer btc
$transaction = Transaction::send();
$transaction->setToBitcoinAddress('here btc address to transfer');
$transaction->setAmount(new Money(0.0010, CurrencyCode::BTC));
$transaction->setDescription('this is optional');
Hope it will work :
https://github.com/coinbase/coinbase-php
Here the code for php
please have a look
<?php
$guid = "GUID_HERE";
$firstpassword = "PASSWORD_HERE";
$secondpassword = "PASSWORD_HERE";
$amounta = "10000000";
$amountb = "400000";
$addressa = "1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq";
$addressb = "1ExD2je6UNxL5oSu6iPUhn9Ta7UrN8bjBy";
$recipients = urlencode('{
"' . $addressa . '": ' . $amounta . ',
"' . $addressb . '": ' . $amountb . '
}');
$json_url = "http://blockchain.info/merchant/$guid/sendmany?password=$firstpassword&second_password=$secondpassword&recipients=$recipients";
$json_data = file_get_contents($json_url);
$json_feed = json_decode($json_data);
$message = $json_feed->message;
$txid = $json_feed->tx_hash;
?>
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);
}
I want to update User table of DATA BROWSER using objectId(With out getting user to log in ) using following code.
But I am getting:
error({"code":101,"error":"object not found for update"})
can any one tell me what is wrong with this:
$className = "Classname";
$objectIdToEdit = $_SESSION['objectId'];
$url = 'https://api.parse.com/1/classes/' . $className . '/' . $objectIdToEdit;
$appId = '***********************';
$restKey = '***********';
$updatedData = '{"firstname":"Billie123"}';
$rest = curl_init();
curl_setopt($rest,CURLOPT_URL,$url);
curl_setopt($rest,CURLOPT_PORT,443);
curl_setopt($rest,CURLOPT_CUSTOMREQUEST,"PUT");
curl_setopt($rest,CURLOPT_RETURNTRANSFER, true);
curl_setopt($rest,CURLOPT_POSTFIELDS,$updatedData);
curl_setopt($rest,CURLOPT_HTTPHEADER, array(
"X-Parse-Application-Id: " . $appId,
"X-Parse-Master-Key: " . $restKey,
"Content-Type: application/json")
);
$response = curl_exec($rest);
echo $response;
I solved problem my self ,URL I was using is to save data
$url = 'https://api.parse.com/1/classes/' . $className . '/' . $objectIdToEdit;
I just changed URL to update data and problem is solved
$url = 'https://api.parse.com/1/' . $className . '/' . $objectIdToEdit;
thanks Ghost for editing
I am able to get access_token for multiple permissions like emails, contacts, docs, etc. using oAuth 2.0. I have access_token
I got contacts using the following code.
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max- results='.$max_results.'&oauth_token='.$access_token;
$response_contacts= curl_get_file_contents($url);
Now i want to get users Emails using this access_token.
i used this url . but it gives 401 unauthorized Error
$url = 'https://mail.google.com/mail/feed/atom&oauth_token='.$access_token;
$response_emails= curl_get_file_contents($url);
please guide me how can i get emails using access_token.
I've seen references to the Gmail feed using oauth_token as a request parameter. However, once I used the OAuth Playground I discovered that you need to pass your OAuth information as an Authorization header, as you'll see below.
<?php
$now = time();
$consumer = ...; // your own value here
$secret = ...; // your own value here
$nonce = ...; // same value you've been using
$algo = "sha1";
$sigmeth = "HMAC-SHA1";
$av = "1.0";
$scope = "https://mail.google.com/mail/feed/atom";
$path = $scope;
$auth = ...; // an object containing outputs of OAuthGetAccessToken
$args = "oauth_consumer_key=" . urlencode($consumer) .
"&oauth_nonce=" . urlencode($nonce) .
"&oauth_signature_method=" . urlencode($sigmeth) .
"&oauth_timestamp=" . urlencode($now) .
"&oauth_token=" . urlencode($auth->oauth_token) .
"&oauth_version=" . urlencode($av);
$base = "GET&" . urlencode($path) . "&" . urlencode($args);
$sig = base64_encode(hash_hmac($algo, $base,
"{$secret}&{$auth->oauth_token_secret}", true));
$url = $path . "?oauth_signature=" . urlencode($sig) . "&" . $args;
// Create a stream
$opts = array(
"http" => array(
"method" => "GET",
"header" => "Authorization: OAuth " .
"oauth_version=\"{$av}\", " .
"oauth_nonce=\"{$nonce}\", " .
"oauth_timestamp=\"{$now}\", " .
"oauth_consumer_key=\"{$consumer}\", " .
"oauth_token=\"{$auth->oauth_token}\", " .
"oauth_signature_method=\"{$sigmeth}\", " .
"oauth_signature=\"{$sig}\"\r\n"
)
);
$context = stream_context_create($opts);
$out = file_get_contents($path, false, $context);
?>