I am facing a problem when I try to send multiple images in a single MMS. Even their documentation is not clear.
I couldn't find an example online showing the same.
According to their documentation about MMS
Up to 10 images that together total no more than 5mb can be sent at one time.
MMS is also only available in the US and Canada.
You can pass the images by using an array like so.
URL method: (urls have to be publicly accessible)
<?php
// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
// Find your Account Sid and Auth Token at twilio.com/console
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$twilio = new Client($sid, $token);
$mediaUrls = array("https://demo.twilio.com/owl.png", "url2", "url3", "url4");
$message = $twilio->messages
->create("+12316851234", // to
array(
"body" => "Hello there!",
"from" => "+15555555555",
"mediaUrl" => $mediaUrls
)
);
print($message->sid);
Documentation:
https://www.twilio.com/docs/sms/api/media-resource
https://www.twilio.com/docs/sms/send-messages?code-sample=code-send-an-mms-message&code-language=PHP&code-sdk-version=5.x
More information about this here https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-php
Related
So, I have a GKE-based function that does processing on an image file. I want this function to be triggered whenever a new file gets dumped into a bucket, using Pub/Sub. I have an external system that pushes the image file into the bucket. I was using object notifications to do this, now I want to use Pub/Sub.
Can I create a notification in GoogleCloudStorage that generates the Pub/Sub notification that my processing function will be pulling? I was looking at the PHP library (https://googleapis.github.io/google-cloud-php/#/docs/google-cloud/v0.162.0/storage/notification) to do this, but the documentation is ridiculously inadequate.
This code creates a notification, but seems strange that I should be supplying a notification ID, and I'm not sure what the payload is going to be...
$client=new StorageClient(['projectId'=><my project>, 'keyFile'=><key file contents>]);
$bucket_name = <my bucket name>;
$notification_id = '2482'; // ?????
$notification_params = [
'eventType' => 'OBJECT_FINALIZE',
'payloadFormat' => 'JSON_API_V1',
'bucketId' => $bucket_name,
];
$bucket = $client->bucket( $bucket_name );
$notification = $bucket->notification( $notification_id );
Is this the correct way to create the notification I want? Do I specify my own id in this way? What happens if there is a collision?
thanks,
andy
Yes it is possible to create a Pub/Sub notification when an object was pushed into the bucket.You need to first create a Pub/Sub topic and subscriber prior to creating the notification.
I used the sample code create pub/sub notification and just add defining of storage bucket:
use Google\Cloud\Core\Iam\PolicyBuilder;
use Google\Cloud\PubSub\PubSubClient;
use Google\Cloud\Storage\StorageClient;
$storage = new StorageClient();
$bucket = $storage->bucket('your-bucket'); // define bucket to be used
$pubSub = new PubSubClient();
$topicName = 'your-topic'; // define the topic to be used
// grant pubsub publisher role for topic
$serviceAccountEmail = $storage->getServiceAccount();
$topic = $pubSub->topic($topicName);
$iam = $topic->iam();
$updatedPolicy = (new PolicyBuilder($iam->policy()))
->addBinding('roles/pubsub.publisher', [
"serviceAccount:$serviceAccountEmail"
])
->result();
$iam->setPolicy($updatedPolicy);
$notification = $bucket->createNotification($topicName, [
'event_types' => [
'OBJECT_DELETE',
'OBJECT_METADATA_UPDATE'
]
]);
To test this, when the pub/sub notification is created:
Push an object in your bucket
Topic should send a message to the subscribers
Check message in the subscriber
Pushed object in test bucket:
Message/notification published to subscribers:
Context
I am trying to make webservice that fetches the name and email from an users Apple account and place a Song or Artist in his library.
For adding a Song to the library I found this apple-music-api. library. To make requests on behalf of a user you need to request a user token with Apple MusicKit JS library.
For fetching the name and email of the user I use this oauth2 client that uses the signin with Apple functionality.
Problem
A Using the apple music kit... I can not query any user profile data. At least I cannot seem to find an example nor any documentation of this. Is there a possibility to get the user email and name using this route?
B Using the Sign in with Apple oauth flow I receive an access token which contains the name and email. But I cannot use the token to query the apple music api. It seems their scopes are limited to the name and email...and no scope for the music api or related seems to exist. Is there a possibility to get an user token that can be used on the music api?
C Are there any other possibilities to accomplish this without requiring the user to sign in twice on apple (once for the email and once for pushing the Song to his library)
What I tried for option B
// $leeway is needed for clock skew
Firebase\JWT\JWT::$leeway = 60;
$provider = new League\OAuth2\Client\Provider\Apple([
'clientId' => 'com.myapp.www',
'teamId' => 'team.id', // 1A234BFK46 https://developer.apple.com/account/#/membership/ (Team ID)
'keyFileId' => 'key.id', // 1ABC6523AA https://developer.apple.com/account/resources/authkeys/list (Key ID)
'keyFilePath' => dirname(__FILE__) . '/AuthKey_key.id.p8', // __DIR__ . '/AuthKey_1ABC6523AA.p8' -> Download key above
'redirectUri' => PLUGIN_URL . 'callback-apple-music.php',
]);
if (isset($_POST['code'])) {
if (empty($_POST['state']) || !isset($_COOKIE['apple-oauth2state']) || ($_POST['state'] !== $_SESSION['apple-oauth2state'])) {
unset($_COOKIE['apple-oauth2state']);
exit('Invalid state');
} else {
try {
// Try to get an access token (using the authorization code grant) via signin_with_apple
/** #var AppleAccessToken $token */
$token = $provider->getAccessToken('authorization_code', [
'code' => $_POST['code']
]);
$access_token = $token->getToken();
// create an client for api.music.apple
$tokenGenerator = new PouleR\AppleMusicAPI\AppleMusicAPITokenGenerator();
$jwtToken = $tokenGenerator->generateDeveloperToken(
'team.id',
'key.id',
dirname(__FILE__) .'/AuthKey_key.id.p8'
);
// create a developer token again
$curl = new \Symfony\Component\HttpClient\CurlHttpClient();
$client = new PouleR\AppleMusicAPI\APIClient($curl);
$client->setDeveloperToken($jwtToken);
$api = new PouleR\AppleMusicAPI\AppleMusicAPI($client);
$api->setMusicUserToken($access_token);
// This endpoint needs authorisation
$result = $api->getAllLibraryPlaylists(); //https://api.music.apple.com/v1/me/library/playlists?offset=0&limit=25
echo '<pre>';
print_r($result);
echo '</pre>';
// wp_redirect($redirect_url);
exit;
} catch (Exception $e) {
echo '<pre>';
print_r($e);
echo '</pre>';
}
}
}
The problem with the question is that these are three questions - and not telling which client.
Most commonly "login with" is only good for creating local accounts without much typing.
And it is quite likely intentional, that the oAuth2 scope is extremely limited for this purpose.
And I've looked it up ...one needs a "Music User Token":
https://developer.apple.com/documentation/applemusicapi/getting_keys_and_creating_tokens
And this token needs to be passed as HTTP header: 'Music-User-Token: [music user token]'.
Which means, that the user token may either originate from an iOS device (you'd need to expose eg. a REST API, so that it can be posted and then used by PHP as HTTP header, on the server-side): https://developer.apple.com/documentation/storekit/skcloudservicecontroller/2909079-requestusertoken (this only requires a login to your own API).
When running Apple MusicKit JS on the cient-side (browser), two logins may not be evitable:
https://developer.apple.com/documentation/musickitjs/musickit/musickitinstance/2992701-authorize
It makes no sense to use both of these flows within the same method(which also ignores the principle of single responsibility).
I have created an account and add Twilio sandbox number for WhatsApp. After following instructions (To begin testing, connect to your sandbox by sending a WhatsApp message from your device to +1 415 523 **** with code join doubt-pupil. ) I have received a file in my WhatsApp number.
Code (PHP - Laravel):
$sid = config('app.TWILIO_SID');
$token = config('app.TWILIO_AUTH_TOKEN');
$twilio = new Client($sid, $token);
$message = $twilio->messages ->create("whatsapp:+9199740*****",
array(
"body" => "AlQuran4Life_invoice_".$invoice->formonth."",
"mediaUrl" => ["PDFURL"],
"from" => "whatsapp:+1415523*****",
)
);
After that I have added balance on Twilio. Now I want to make it live to send invoice to WhatsApp number.
What credentials I need to update? Or which phone number do I need to update?
How can I get locations list in Google My Business API. Where I retrieved account list but I can't figure out how to retrieve location.
Here is my code where I am getting accounts list
define('GOOGLE_CLIENT_ID', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
define('GOOGLE_CLIENT_SECRET', 'XXXXXXXXXXXXX');
// Create Client Request to access Google API
$client = new Client();
$client->setApplicationName('my-app');
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setRedirectUri('https://example.com/callback');
$client->addScope('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/business.manage');
$client->setAccessType('offline'); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->setAccessToken($accessToken);
$service = new \Google_Service_MyBusinessAccountManagement($client);
$accounts = $service->accounts->listAccounts()->getAccounts(); // get accounts
To get google locations,
you can use this PHP My Business file to make things little easier.
First change you scope to ttps://www.googleapis.com/auth/plus.business.manage then include the file and create a object of Google_Service_MyBusiness with you client and then do like this.
$mybusinessService = new Google_Service_MyBusiness($client);
// Get the first account in the accounts array
$accounts = $mybusinessService->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
$account = $accountsList[0];
// Get the first location in the locations array
$locations = $mybusinessService->accounts_locations;
$locationsList = $locations->listAccountsLocations($account->name)->getLocations();
$location = $locationsList[0];
var_export($location);
With this process you can also able to get google reviews.
For more details check this Google Business API documentation.
Hope it can help
"It's correct!!!
I increase this at my code:
$optParams = array(
'readMask' => 'name',
);
$list_accounts_response = $my_business_account->accounts_locations->listAccountsLocations("accounts/114893266195214446586", $optParams);
var_dump($list_accounts_response);
Thank you.."
source : https://github.com/googleapis/google-api-php-client/issues/2213#issuecomment-1042785983
I am using Twilio's PHP SDK to send SMS. Below is the code:
<?php
// Required if your environment does not handle autoloading
require './autoload.php';
// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$sid = 'XXXXXXXXXXXXXXXXXXXXXXXX';
$token = 'XXXXXXXXXXXXXXXXXXXX';
$client = new Client($sid, $token);
// Use the client to do fun stuff like send text messages!
$client->messages->create(
// the number you'd like to send the message to
'+XXXXXXXXXX',
array(
// A Twilio phone number you purchased at twilio.com/console
'from' => '+XXXXXXXX',
// the body of the text message you'd like to send
'body' => 'Hey Jenny! Good luck on the bar exam!'
)
);
**Response:
[Twilio.Api.V2010.MessageInstance accountSid=XXXXXXXXXXXXXXXX sid=XXXXXXXXXXXXXXX]**
How I can get the response in JSON Format?
Any help is appreciated.
I'm not sure if I have understood your intent properly, however, I've created a new GitHub repository which I hope gives you the information that you're after, if you're still interested.
The MessageInstance object which the call to $client->messages->create() returns won't return anything of value when passed to json_encode(). This is because the relevant properties are contained in a protected property, so json_encode() cannot access them.
One option to get around this is to use a class which implements JsonSerializable and returns a JSON representation of a MessageInstance object, such as JsonMessageInstance.
Have a look at the code and let me know if this does what you wanted.
The quick answer is:
$json_string = json_encode(</POST|GET>);
Use the $_POST or $_GET super globals and you get a json string format.
e.g.
/*
* Imagine this is the POST request
*
* $_POST = [
* 'foo' => 'Hello',
* 'bar' => 'World!'
* ];
*
*/
$json_string = json_encode($_POST); // You get → {"foo":"Hello","bar":"World!"}
In this way you encode the values in a JSON representation.