According the docs for the Messenger Platform 1.4, the Upload API returns an attachment_id for the uploaded attachment:
{
"attachment_id":"1854626884821032"
}
How do we use this attachment_id to send attachments? Or does simply sending another message with an attachment from the same URL result in messenger using the uploaded attachment?
You should use
$imageAttachment = array('type' => 'image'``, 'payload' => array('attachment_id' => '1854626884821032'));
$params = array('message' => array('attachment' => $imageAttachment), "recipient" => array("id" => $senderId));
and the make a Curl as specified here
https://developers.facebook.com/docs/messenger-platform/send-api-reference/image-attachment
Related
Is it possible to connect to an API with windows Credentials?
I need to connect on an API witch uses Windows AD authentication.
I thought thats works with auth_basic but it's not the good way...
Thanks by advance for your answers
$httpClient = HttpClient::create([
'auth_basic' => ['username', 'password']
]);
$response = $httpClient->request('GET', 'https://apiURL', [
'headers' => ['accept' => 'text/plain'],
]);
dump($response->getStatusCode());
dump($response);
Yes, it's possibile using the auth_ntlm option. But this option is supported only by the cURL client, so you must have the cURL PHP extension installed and enabled in your system.
Here's the code:
$httpClient = new CurlHttpClient(['auth_ntlm' => "username:password"]);
$response = $httpClient->request('GET', 'https://apiURL', [
'headers' => ['accept' => 'text/plain'],
]);
dump($response->getStatusCode());
dump($response);
I am trying to work with the WooCommerce REST API. So far I have installed the official package and created an index.php file with this code in it:
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;
$woocommerce = new Client(
'http://me.commerce.loc/', // Your store URL
'ck_9dadcf73d58fec8b0860bced4b0997d7b3b0f93e', // Your consumer key
'cs_e63d694c035444c45355339171c682052b2707eb', // Your consumer secret
[
'wp_api' => true, // Enable the WP REST API integration
'version' => 'wc/v3' // WooCommerce WP REST API version
]
);
print "<pre>";
print_r($woocommerce);
die();
Printing out $woocommerce gives me this object:
Automattic\WooCommerce\Client Object
(
[http] => Automattic\WooCommerce\HttpClient\HttpClient Object
(
[ch:protected] =>
[url:protected] => http://me.commerce.loc/wp-json/wc/v3/
[consumerKey:protected] => ck_9dadcf73d58fec8b0860bced4b0997d7b3b0f93e
[consumerSecret:protected] => cs_e63d694c035444c45355339171c682052b2707eb
[options:protected] => Automattic\WooCommerce\HttpClient\Options Object
(
[options:Automattic\WooCommerce\HttpClient\Options:private] => Array
(
[wp_api] => 1
[version] => wc/v3
)
)
[request:Automattic\WooCommerce\HttpClient\HttpClient:private] =>
[response:Automattic\WooCommerce\HttpClient\HttpClient:private] =>
[responseHeaders:Automattic\WooCommerce\HttpClient\HttpClient:private] =>
)
)
Is it possible to get wooCommerce data through this object? If no then how can I do it?
Thank you very much.
You do not require to add above code or create index.php
just use this end point to get all orders list : https://example.com/wp-json/wc/v3/orders
To get all Products : https://example.com/wp-json/wc/v3/products
This way you can get list of order and products.
To use rest api and do all operations in woocommerce using rest api please refer this link : https://woocommerce.github.io/woocommerce-rest-api-docs/
There are two woocommerce rest api versions which are V2 and V3 you can use any from this.
the API works when ck_ and cs_ keys are for Admin and returns the std class object but when keys are for a different user returns You do not have permission to read this product 401(woocommerce_api_user_cannot_read_product) Error response: even when user has read/write privileges. but goes ahead to create the product in the database. Any help on this issue is highly appreciated
require_once( 'lib/woocommerce-api.php' );
$options = array(
'debug' => true,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 30,
'ssl_verify' => false,
);
try {
$client = new WC_API_Client( $the_url, 'ck_xxxx', 'cs_xxxx', $options);
Try adding into your $options array:
$options['query_string_auth'] = true;
As noted in the documentation this will "Force Basic Authentication as query string true" in other words it will append your consumer key and consumer secret to your request URL as a query string. This is only supported on HTTPS.
I create my first app with silex. Only logged in users can use the app. In the first page i create a login form, so the user can authenticate. My security provider look like:
$app->register(new Silex\Provider\SecurityServiceProvider(), array(
'security.firewalls' => array(
'secure_area_edison' => array(
'pattern' => '^/admin/',
'form' => array('login_path' => '/', 'check_path' => '/admin/login_check'),
'logout' => array('logout_path' => '/admin/logout', 'invalidate_session' => true),
'users' => function () use ($app) {
return new App\Services\UserProvider($app['db']);
},
),
)
));
Every url after '/admin' require that the user was successfull authenticated. Everything works fine and now i want to extend my app with an API. I create a new controller which retrieves data from database and return a JSON reponse, this work also fine.
But how can the user authenticate for this API? Should i create a new column in my user table like "hash" or "token"? Users which will retrieve the JSON Response must send the token in every get request, is this the correct way?
The url can look:
/admin/api/allProducts/token/<TOKEN>
you should use token base authentication instead of passing token in every get request.
refer : https://github.com/thcolin/silex-simpleuser-jwt
I'm currently stuck with some of Zend's methods, im trying to make a simple Zend_Service_Twitter request through a proxy, however i keep getting:
Unable to Connect to tcp://api.twitter.com:80. Error #0:
php_network_getaddresses: gethostbyname failed.
I am able to do http calls with the Zend_Http_Client library by itself, so I believe my problem is with the code where I pass the httpClient instance to the Zend_Service_Twitter... But enough rant i guess, basically I have the following:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Proxy',
'proxy_host' => self::PROXY_HOST,
'proxy_port' => self::PROXY_PORT,
'timeout' => 240,
);
$httpClient = new Zend_Http_Client(self::TWITTER_API_URL, $config);
$token = new Zend_Oauth_Token_Access;
$token->setParams(array(
Zend_Oauth_Token_Access::TOKEN_PARAM_KEY => self::TWITTER_OAUTH_TOKEN,
Zend_Oauth_Token_Access::TOKEN_SECRET_PARAM_KEY => self::TWITTER_OAUTH_TOKEN_SECRET
));
$twitter = new Zend_Service_Twitter(array(
'username' => 'MYUSERNAME',
'accessToken' => $token
));
$twitter->getHttpClient($httpClient);
$response = $twitter->account->rateLimitStatus();
Any pointers would be appreciated!
While taking a closer look at the Zend_Service_Twitter class, all you need to do in order to set up the proxy parameters is this:
$twitter = new Zend_Service_Twitter(array(
'username' => 'MYUSERNAME',
'accessToken' => $token
));
$twitter->setLocalHttpClient($twitter->getHttpClient($httpClient));
($httpClient being an instance of Zend_Http_Client which contains your proxy configuration)