Twilio Whatsapp API - Specify Local Image Path in PHP Server - php

Looking for a way to specify image path that's stored in local server in Whatsapp twilio api. I can send image via api using hosted image links but having difficulty specifying local file path. Can you help?
<?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
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);
$message = $twilio->messages
->create("whatsapp:+15017122661", // to
[
"mediaUrl" => ["https://images.unsplash.com/photo-1545093149-618ce3bcf49d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=668&q=80"],
"from" => "whatsapp:+14155238886"
]
);
print($message->sid);
?>
In short, I want to know whether i can attach local image file to the message using the mediaURL attribute.

When Twilio processes your request to send an MMS or a WhatsApp Message with an mediaUrl, Twilio will retrieve the file from the Media URL that you provided. However, Twilio cannot access your localhost network.
First, make sure the media files are served by your web server.
Then, during development, you can tunnel your localhost network to the public internet using tools like ngrok. You'd run a command like this:
ngrok http https://localhost:5000
https://localhost:5000 should be replaced with the localhost URL to the web server serving your media locally.
The output will display the public Forwarding URL created by ngrok. Any HTTP request to this Forwarding URL will be forwarded to your application listening to https://localhost:5000. Use this public Forwarding URL with the path to your file, as your Media URL and Twilio should be able to retrieve it and sent it as an MMS.
When you deploy your application to a web server that is publicly accessible, you won't need a tunnel anymore, but can point to the public domain of where your media is served.
Note, if you don't want your media to be publicly accessible, you can secure your application by validating the HTTP request originates from Twilio.
Alternatively, you can upload your media to a storage service like AWS S3, Azure Storage, Google Cloud Storage, etc.
Make sure the media is publicly accessible and then use the public URL of the uploaded media.

Related

Facebook PHP sdk

I work with facebook php sdk 5 , I create an application facebook . I put domain APP: localhost , AND site URL :http://localhost/facebook-phpExpl/facebook-php-sdk/index.php . I put it as public .I test it it work but now when I connect with other accout it return
Application not configured: This application is currently under development, and you can not access it. Use an authorized user account or contact an application administrator to obtain an access right.
how can I configure application to connect with public users . what can I put in https URL (URL of the Privacy Policy)??
Open the App settings and find the toggle button to set it public under "App Review".
The Privacy Policy is only needed then you go online, it will not work with localhost anyway because Facebook needs to be able to access it.

how to pass youtube api auth and permission response from server to client's webrowser

So I have a Python script that is being run on the server (PHP runs it). However, script has to authenticate user on youtube. When you run it localy it opens the browser, allows to authenticate and asks for permission. Everything works. When I allow users to run it on server, it will try to open the auth screen on server. I need to pass the response to the web browser.
Any ideas?
I use the auth script from the youtube api examples:
# The CLIENT_SECRETS_FILE variable specifies the name of a file that contains
# the OAuth 2.0 information for this application, including its client_id and
# client_secret. You can acquire an OAuth 2.0 client ID and client secret from
# the Google Developers Console at
# https://console.developers.google.com/.
# Please ensure that you have enabled the YouTube Data API for your project.
# For more information about using OAuth2 to access the YouTube Data API, see:
# https://developers.google.com/youtube/v3/guides/authentication
# For more information about the client_secrets.json file format, see:
# https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
CLIENT_SECRETS_FILE = "client_secrets.json"
# This variable defines a message to display if the CLIENT_SECRETS_FILE is
# missing.
MISSING_CLIENT_SECRETS_MESSAGE = """
WARNING: Please configure OAuth 2.0
To make this sample run you will need to populate the client_secrets.json file
found at:
%s
with information from the Developers Console
https://console.developers.google.com/
For more information about the client_secrets.json file format, please visit:
https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
""" % os.path.abspath(os.path.join(os.path.dirname(__file__),
CLIENT_SECRETS_FILE))
# This OAuth 2.0 access scope allows for full read/write access to the
# authenticated user's account.
YOUTUBE_READ_WRITE_SCOPE = "https://www.googleapis.com/auth/youtube"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE,
message=MISSING_CLIENT_SECRETS_MESSAGE,
scope=YOUTUBE_READ_WRITE_SCOPE)
storage = Storage("%s-oauth2.json" % sys.argv[0])
credentials = storage.get()
if credentials is None or credentials.invalid:
flags = argparser.parse_args()
credentials = run_flow(flow, storage, flags)
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
http=credentials.authorize(httplib2.Http()))
The server side webapp is quiet simple, it allows to choose script variation and couple settings, that's all.
When you are authenticating your user credentials in your server, you need to use Oauth2 (in google's case).
It took me some time understanding it in the beginning as well...
The meaning of OAuth2 is that you redirect the user to a login address provided by google, tell the service "look, after the user logged in, send the token to URL X" (your server). Your server gets some sort of token that represents the user authorizing your "app" to do stuff on his behalf.
Check out https://developers.google.com/api-client-library/python/auth/web-app
Specifically in your case - you'll need to implement the endpoint in the PHP (it needs to "listen" on an address if you get my drift)
If you don't really need user credentials and only need to access youtube API as any authenticated user, it is easier - you need to have your own credentials and do "server to server" explained here:
https://developers.google.com/api-client-library/python/auth/service-accounts

YouTube API call fails, even though server’s IP address is white-listed

I’ve a simple PHP component that fetches videos from a public playlist on YouTube. I’m using Google’s official PHP SDK and authenticated with a server key (as I only need to access public data, not data in a user context).
Throughout development and into staging, this component has worked fine. However, I’ve moved the application to the client’s production server (a GoDaddy hosting account) and the component’s suddenly stopped working, instead throwing the following error:
Google_Service_Exception in REST.php line 83:
Error calling GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=PLAYLIST_ID&userIp=SERVER_IP&key=DEVELOPER_KEY: (403) There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.
I don’t understand. The server’s IP address is white-listed in the Google API Console. I know it’s the correct IP address, as I’ve sent a HTTP POST request from the server to another PHP script and captured the REMOTE_ADDR server variable.
I’ve also tried specifying the IP address in the request itself. The full code:
$client = new Google_Client;
$client->setApplicationName($appName);
$client->setDeveloperKey($developerKey);
$service = new Google_Service_YouTube($client);
$service->playlistItems->listPlaylistItems('snippet', array(
'maxResults' => 50,
'playlistId' => $collectionId,
'userIp' => $serverIp,
));
So what’s going? Why is Google deciding it’s not playing ball with the production server?

Zencoder api is working in local but not in Live

I am using Zencoder API for video conversion. I have generated two different API keys for my local and live server.
When I am testing the conversion of video from my local its sending request to Zencoder and working fine. But, when same process I am doing with my live server then its not sending any request to Zencoder API. Using, FTP for sending request and reponse.
My input and output URL generating like
define('INPUT_URL', "ftp://username:password#127.0.0.1/project/upload/");
define('OUTPUT_URL', "ftp://username:password#127.0.0.1/project/upload/");
$inputUrl = INPUT_URL.$fileInfo['file_name'] . '.' . $fileInfo['file_type'];
$outputUrl = OUTPUT_URL.$new_file;
127.0.0.1 written as per example. In my code using my live IP.
Any idea why it may not be working in live?
Thank!

canot establish connection to localhost through facebook application

i have created a new Facebook application and i used the following url as canvas url http://localhost/my_app/
my code works perfectly on localhost, but when i try to cal my application using the following url : apps.facebook.com/leenaaps its displays the following error:
Unable to connect
Firefox can't establish a connection to the server at localhost
what could be the problem exactly?
You most likely do not have a local webserver running. If you do, it might be possible that Facebook uses https:// but you did not configure/enable SSL.
localhost is resolved to ip 127.0.0.1 and this is the local loopback address whcih means it is not routable and cannot be accessed from the internet, So you cannot use it in your canvas url.
You have to use a valid and active domain name like domain.com. If you don't have a public web server you may use some DDNS service, google it some are free

Categories