I am working on Twitter API to create a functionality for the users to tweet directly from the software:
Here is my code:
$connection = new TwitterOAuth($this->getTwitterbpTable()->getConsumerKey(), $this->getTwitterbpTable()->getConsumerSecret(), $account->oauth_token , $account->oauth_secret);
$connection->setTimeouts(10, 150);
$media1 = $connection->upload('media/upload', ['media' => 'https://bleupagereview.files.wordpress.com/2014/02/bleupage.png']);
$parameters = [
'status' => 'My Media tweet here',
'media_ids' => implode(',', [$media1->media_id_string])
];
$connection->post('statuses/update', array('status' => $parameters));
The scripts works fine (does not throw any error/exception), but instead of uploading the file, it simply tweets the media id.
How should I change it so that it uploads the media file with status message.
Post function should be like this:
$connection->post('statuses/update', $parameters);
Related
I am trying to use the mailjet send API for transactional emails from my wordpress website. My mailjet account works fine and I have a contact form that works fine with the mailjet plugin. When the contact form is submitted, an email is sent using mailjet.
Now I want to use the transactional templates from mailjet to replace my actual wp_mail function used in my contact page, because the emails sent using wp_mail doesn't look nice.
I already uploaded the php library (no composer) https://github.com/mailjet/mailjet-apiv3-php-no-composer to my server to the path htdocs/. I created a template on mailjet and published it. The template has the id mentioned in the code below.
This is my code for the send api transactional contact emails.
<form action="" name="contactform" method="post">
...
</form>
<?php
if($emailisright=="OK"){
require_once("/mailjet-apiv3-php-no-composer-master/vendor/autoload.php");
use \src\Mailjet\Resources;
$apikey = '***********************';
$apisecret = '***************************';
$body = [
'Messages' => [
[
'From' => [
'Email' => "no_reply#myemail.com",
'Name' => "Contact mywebsite"
],
'To' => [
[
'Email' => "testemail#gmail.com",
'Name' => "Test email"
]
],
'TemplateID' => 4546355,
'TemplateLanguage' => true,
'Subject' => "Re : contact",
'Variables' => json_decode('{
"name": "Tester",
"mailcc": "testemail#gmail.com",
"message": "test 9"
}', true)
]
]
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
$response->success() && var_dump($response->getData());
}
?>
The page got blank. But when I exclude the following line code //use \src\Mailjet\Resources; then the page renders perfectly, but when submitting the form, I get a broken page which is normal as the line code //use \src\Mailjet\Resources; has been removed. This means that use \src\Mailjet\Resources; seems to be the issue. I also tried with use \Mailjet\Resources; but same broken result.
Now I am not sure I uploaded the php library on the right place on my server. This is the full server path to the wordpress website /opt/bitnami/apps/wordpress/htdocs.
Where do I have to upload the PHP mailjet library?
And where do I have to upload my contact page? On the same level of the mailjet PHP library?
I am trying to obtain the authentication token from the Processmaker to use the APIs. I have used the same API call which works perfectly fine in the test environment, with production urls and respective client id and client secret. But, I am getting below error, although the username and password of the account is correct.
Request:
{
"grant_type": "password",
"scope": "*",
"client_id": "xxxxxx",
"client_secret":"7777777",
"username": "username",
"password": "password"
}
Response:
{
"error": "invalid_client",
"error_description": "The client credentials are invalid"
}
I have tried below steps. But still the same error.
Create a new account without AD user account as the account used in test environment is not a domain account
Change the role of account to 'System Administrator' which is similar to the account in test
**While registering the client to use the APIs, we didn't use the Callback URL as it is optional (we did not configure it in the test environment as well)
Some help is really appreciated, as I have no clue what else to check between the environment to resolve this issue.
I am not sure if you are trying to call API from ProcessMaker to RPA or RPA to ProcessMaker.
For ProcessMaker to RPA:
Using Script: I have built a ProcessMaker script in PHP and with appropriate script configuration, you will be able to run the RPA bot from ProcessMaker.
<?php
/*
* Yo. This script is developed by Abhishek Kadam.
* This script is sufficient to run all the Microbots.
* The Script Configuration contains "release_key" which is the Process ID,
* "robot_id" which is to identify where to run the Bot, "orch_unit_id" which is the folder name
* and "orch_url" which stands for Orchestrator URL. To Run the bot, All the configurations are required.
*/
//******ASSIGNING VARIABLES*****
$client_id = $config['client_id']; // $config to get data from Script Configuration
$refresh_token = $config['refresh_token'];
$release_key = $config['release_key'];
$robot_id = $config['robot_id'];
$orch_url = $config['orch_url'];
$orch_unit_id = $config["orch_unit_id"];
//****** GET ACCESS TOKENS USING CLIENT ID AND REFRESH TOKENS******
$access_token = getAccessToken($client_id,$refresh_token);
$output_response = runBot($access_token,$release_key,$robot_id,$orch_url,$orch_unit_id);
//pass the Access token to runbot() and run the bot ez-pz!
function getAccessToken($client_id,$refresh_token){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://account.uipath.com/oauth/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{\r\n \"grant_type\": \"refresh_token\",\r\n \"client_id\": \"".$client_id."\",\r\n \"refresh_token\": \"".$refresh_token."\"\r\n}",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
curl_close($curl);
$responseDecode = json_decode($response);
$accessToken= $responseDecode -> access_token; //get the access token
return $accessToken;
}
function runBot($access_token,$release_key,$robot_id,$orch_url,$orch_unit_id){
$curl = curl_init(); //Not sure if it's the right way to initialize or not but meh, it works :P
curl_setopt_array($curl, array(
CURLOPT_URL => $orch_url."/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{ \"startInfo\":\r\n { \"ReleaseKey\": \"".$release_key."\",\r\n \"Strategy\": \"Specific\",\r\n \"RobotIds\": [ ".$robot_id."],\r\n \"JobsCount\": 0,\r\n \"Source\": \"Manual\" \r\n } \r\n}",
// Release key and Robot ID can be concatenated and passed as an argument(once I figure out how to get arguments in PM 4 scripts)
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Bearer ".$access_token,
"X-UIPATH-OrganizationUnitId: ".$orch_unit_id
//There's another way to use the Access token. For now, I found this more helpful.
//As the document is TL;DR. https://www.php.net/manual/en/function.curl-setopt.php
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
//echo $response; //Print Response cuz why not? ;)
}
return [$access_token];
?>
I had used the UiPath RPA tool for this without mentioning any callback URL.
Using Data Connectors: Create Data Connectors in ProcessMaker. I prefer to using the Postman application before creating DC. Refer: Postman to UiPath Bot
For RPA Bot to ProcessMaker
In ProcessMaker documentation you can see the Swagger Link for your particular instance. The Swagger Documentation for ProcessMaker was not really helpful. There are few mistakes in the documentation provided.
For ease, I did import the API collection in Postman and proceeded with creating variables: baseURL & accessToken
baseURL: Your URL (https://something.processmaker.net)
ADD /api/1.0
/api/1.0 (https://something.processmaker.net/api/1.0)
Now the URL is correct. Also while sending the request make sure Params are not empty.
Note: For Access Token, Admin --> Users --> Edit --> API Tokens --> Create new Token --> Copy Token.
In Processmaker 4, API tokens are available for individual Users.
I hope this will help you in a way. Thanks!
I'm trying to share a video to Twitter Account but getting a response like below
stdClass Object ( [request] => /1.1/media/upload.json [error] => Segments do not add up to provided total file size. [httpstatus] => 400 [rate] => stdClass Object ( [limit] => 615 [remaining] => 613 [reset] => 1576651447 ) )
I don't know what to do to fix this issue. If anyone experienced this please let me know.
This is my code to share video to twitter.
\Codebird\Codebird::setConsumerKey(CONSUMER_KEY, CONSUMER_SECRET);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken($access_token, $access_token_secret);
$file = $videopath;
$size_bytes = filesize($file);
$fp = fopen($file, 'r');
// INIT
$reply = $cb->media_upload([
'command' => 'INIT',
'media_type' => 'video/mp4',
'total_bytes' => $size_bytes
]);
$media_id = $reply->media_id_string;
// APPEND
$segment_id = 0;
while (! feof($fp)) {
$chunk = fread($fp, 1048576); // 1MB per chunk for this sample
$reply = $cb->media_upload([
'command' => 'APPEND',
'media_id' => $media_id,
'segment_index' => $segment_id,
'media' => $chunk
]);
$segment_id++;
}
fclose($fp);
// FINALIZE
$reply = $cb->media_upload([
'command' => 'FINALIZE',
'media_id' => $media_id
]);
if ($reply->httpstatus < 200 || $reply->httpstatus > 299) {
die();
}
// Now use the media_id in a Tweet
$reply = $cb->statuses_update([
'status' => $msg,
'media_ids' => $media_id
]);
I'm getting an error in the Finalize command result.
I tried to fix this but I can't because I don't know the exact reason for this issue and I didn't know how to handle and fix this. Can anyone help me to fix this? The above is the code I have used to share the post to the twitter account. And one thing is, the above code works fine when I tried to share the post immediately to twitter using this API but the issue is only when I tried to share the post by scheduling it with a specific time to share.
And when I trying to share a video below 1mb it gets shared. When I tried a video with 1mb or more than that I got the below error while sharing to account.
{"errors":[{"code":324,"message":"Invalid media id 1215261697298108416"}],"httpstatus":400,"rate":null}
I am looking for an example for web push notification with JS code and PHP backend. Can anyone share example code or a tutorial?
Here's a basic example that uses web-push-php : https://github.com/Minishlink/web-push-php-example
Main PHP code is:
<?php
require __DIR__ . '/vendor/autoload.php';
use Minishlink\WebPush\WebPush;
$auth = array(
'VAPID' => array(
'subject' => 'https://github.com/Minishlink/web-push-php-example/',
'publicKey' => 'BCmti7ScwxxVAlB7WAyxoOXtV7J8vVCXwEDIFXjKvD-ma-yJx_eHJLdADyyzzTKRGb395bSAtxlh4wuDycO3Ih4',
'privateKey' => 'HJweeF64L35gw5YLECa-K7hwp3LLfcKtpdRNK8C_fPQ', // in the real world, this would be in a secret file
),
);
$webPush = new WebPush($auth);
$res = $webPush->sendNotification(
$subscription['endpoint'],
"Hello!", // payload
$subscription['key'],
$subscription['token'],
true // flush
);
// handle eventual errors here, and remove the subscription from your server if it is expired
Hope this helps :)
We have recently create the google marketplace app and published as public .admin of the google apps domain users can able to install it .
i recently try to implement the CustomerLicense,LicenseNotification Apis in for my app
But i dont know how to send a Authorization for it Please suggest me to how to do this
My requirement :
1.I need to know whether the given domain has installed my marketplace app or not (My input is authorization,email id or domain name
2.If any user uninstall or revoke the data access for my marketplace app i need to get the notify (optional)
Here is sample code :
$appId = '';**//Where i get this**
$userid = '';**//It is emailid or domain name or user unique numeric id**/
$oauthOptions = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'signatureMethod' => 'HMAC-SHA1',
'consumerKey' => '', **//Where i get this**
'consumerSecret' => "" **//Where i get this**
);
//We get from APP URL
try {
$userid = 'backup-testing.in';
$token = new Zend_Oauth_Token_Access();
$client = $token->getHttpClient($oauthOptions);
$url = "https://www.googleapis.com/appsmarket/v2/customerLicense/$appId/$userid";
$client->setMethod(Zend_Http_Client::GET);
$gdata_put = new Zend_Gdata($client);
$resultR = $gdata_put->get($url);
} catch (Exception $e) {
var_dump($e);
}
This is my marketplace app
in chrome westore : https://chrome.google.com/webstore/detail/gapps-backup/jmjnfmekbahcminibjmedfehecoihglj
Here you can find information about the Licensing API https://developers.google.com/google-apps/marketplace/v2/developers_guide which i think will be useful for what you want to do. hope it helps.