Mentioning blogs using Tumblr API / PHP SDK - php

I'm creating an integration that allows people to post on Tumblr. It seems to work well, except that I can't figure out how to mention people using the API.
Tumblrs docs only mention how to do it using the impossible Neue Post Format, which the PHP SDK doesn't seem to support. The legacy format doesn't show it.
Am I missing something? Or will I have to make manual calls using the new format?
require __DIR__ . '/vendor/autoload.php'; // composer tumblr/tumblr version 0.4.0
$client = new Tumblr\API\Client($consumerKey, $consumerSecret);
$client->setToken($token, $tokenSecret);
$data = array(
"type" => 'text',
"body" => $body,
"tags" => $tagString
);
$client->createPost($blogName, $data);
Expected result:
create a post that has a clickable link to the mentioned person.
Actual result:
The mentioned name is posted as plain text.
How do I solve this problem?

Related

How to return all Campaign information for a specific user by calling the Facebook market API using the Facebook-business-php-sdk

I'm trying to get all campaign IDs using the supplied code from the API graph explore tool but the code supplied by the Graph API tool returns and error.
The Facebook initialization code is below
$api = new \Facebook\Facebook([
'app_id' => '00000',
'app_secret' => '0000',
]);
When I run the following code:
$response = $api->get(
'/act_0000000/campaigns',
'{Token}'
);
The following error is returned:
You are calling a deprecated version of the Ads API. Please update to the latest version: v3.2.
Or when I update the code to match what is specified as the latest version:
$response = $api->get(
'v3.3/act_0000000/campaigns',
'{Token}'
);
Then the following error is returned:
Unknown path components: /act_00000000/campaigns
I've tried using the Raw SDK but the documentation seems to be either depreciated or not working all together. Any help or advice is greatly appreciated, I could use the cURL method but id rather use the raw SDK.
The way i was able to resolve the issue was by running the following code, the docs seems to only be updated on the Facebook-business-php-sdk GitHub link
you could either manually pass the string to the AdAccount() like i id or dynamically though a for-each.
Api::init($app_id, $app_secret, $access_token);
Api::instance();
$data = new AdAccount('act_00000');
$results = $data->getCampaigns(['id', 'name']);

DialogFlow - How to Batch Update Intents via API?

I'm looking for a basic example on how to utilize DialogFlow's batchUpdate, and how to utilize batchUpdateResponse to show an actual response once complete.
Have found no examples for DialogFlow V1 or V2 (at this point either would be helpful), the below is all I've managed to setup - looking for the missing arguments to be added:
$intentsClient->batchUpdateIntents($formattedParent, $languageCode, $test_3);
Currently using PHP https://github.com/googleapis/google-cloud-php/tree/83ae284c025f6e93b9ce835b987932c425b5a9de/Dialogflow but any language is fine here.
Ended up figuring this out through the use of https://developers.google.com/apis-explorer/ and the Google Client Library for PHP (https://github.com/googleapis/google-api-php-client).
Below is a basic example for updating the text on two intents at once, via PHP. Hopefully this helps someone in the future, am somewhat surprised at the general lack of helpful documentation and/or examples for using DialogFlow's API V2 (or even V1 for that matter). So many awesome things can be done by using this rather than their Dashboard to train your bot!
// Global variable pointing to the .json file downloaded with private key from DialogFlow
putenv('GOOGLE_APPLICATION_CREDENTIALS=directory-of-file/google-service-acount-key.json');
// Setup Google Client
require __DIR__.'/vendor/autoload.php';
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/cloud-platform');
$httpClient = $client->authorize();
// Setup array to update intent (minified)
$update_intent = array('intentBatchInline'=>array('intents'=>array(
0=>array('name'=>'projects/YOUR-PROJECT-NAME/agent/intents/FIRST-INTENT-ID','displayName'=>'FIRST-INTENT-NAME','messages'=>array(0=>array('text'=>array('text'=>array(0=>'FIRST-INTENT-TEXT-TO-UPDATE',),),),),),
1=>array('name'=>'projects/YOUR-PROJECT-NAME/agent/intents/SECOND-INTENT-ID','displayName'=>'SECOND-INTENT-NAME','messages'=>array(0=>array('text'=>array('text'=>array(0=>'SECOND-INTENT-TEXT-TO-UPDATE',),),),),),),),
);
// Post to DialogFlow API
$response = $httpClient->post('https://dialogflow.googleapis.com/v2/projects/PROJECT-NAME-HERE/agent/intents:batchUpdate', [
GuzzleHttp\RequestOptions::JSON => $test_batch_intent_1
]);
// Print out response for troubleshooting
print_r($response->getBody()->getContents());
echo "<br /><br />Here's to getting past DialogFlow API's hurdles! :)";
exit;
This is similar to my answer. Where I have given a complete example. Do check it out.
Stack Overflow answer.
And this is based out of NodeJs. As you told the language does not matter.
And do check out this documentation for different kinds of examples. This document covers even the batchUpdate functionality.
Please check these out:
GitHub repo
GitHub repo

Shopify Webhooks work in testing but not in practice

I'm having some problems with my Shopify 'orders/paid' webhook that I install onto the users store via the Shopify SDK (using a PHP wrapper: https://github.com/phpclassic/php-shopify). Anyways, I create the webhook like so:
$shop = $this->request->getVar('shop'); // Get Shopify store URL
// Get access token for store
$config = array('ShopUrl' => $shop, 'ApiKey' => 'xxx', 'SharedSecret' => 'xxx');
\PHPShopify\ShopifySDK::config($config);
$accessToken = \PHPShopify\AuthHelper::getAccessToken();
// Keep track of access_token for SDK calls and authenticate to store for webhook creation
$addToken = $this->Stores->addAccessToken($shop, $accessToken);
$config = array('AccessToken' => $accessToken, 'ShopUrl' => $shop);
$shopify = new \PHPShopify\ShopifySDK($config);
// Create orders/paid webhook
$orderPaidHook = array('topic' => 'orders/paid', 'address' => 'https://api.autoloapp.com/webhook/create', 'format' => 'json');
try {
$webhooks = $shopify->Webhook->post($orderPaidHook);
}
This code as far as I can tell works, using print_r($webhooks) gives me a valid Webhook that has (in theory) been installed on to the store. However, when an order is actually paid for on the store I DO NOT get a message.
Using the "Test Webhook" settings under "Notification" in the Shopify Admin my webhook works perfectly. Using PostMan to simulate a webhook call works perfectly.
The code to process the webhook looks like this:
$headers = getallheaders();
$topic = $headers['X-Shopify-Topic'];
$storeName = $headers['X-Shopify-Shop-Domain'];
if ($topic == 'orders/paid') {
// Do some stuff, insert row into database
}
Again, when I use PostMan or the built-in "Test Webhook" setting for Shopify the row in my database gets created just fine. When I do it with a real webhook nothing happens. I'm not sure why this is happening, as far as I know all the headers should be the same. Do I need to verify the webhook in some way?
For reference I'm using CodeIgniter 4.0, PHP 7.0, and the newest version of the Shopify SDK.
I found this note on Shopify's Docs: "Note that if you are using a Rack based framework such as Ruby on Rails or Sinatra the header you are looking for is HTTP_X_SHOPIFY_HMAC_SHA256". With my current set-up I should still be using X-Shopify-Shop-Domain instead of HTTP_X_Shopify_Shop_Domain correct? Any help greatly appreciated!
So I finally figured out that for some reason the 'orders/paid' webhook wouldn't work for me in "production environments" despite working fine in my test environments. Simply changing the topic to 'orders/create' resolved my problem.

Infusionsoft Getting Tags

I am new to the Infusion API and I have a couple of questions that I am unable to find a specific answer to.
I have used the PHP SDK and installed via composer
1) Within the new API is there away that I can view all tags that have been created?
2) I have created and got my client clientId and clientSecret via but I am unsure how I connect it to the app name that I want to fetch the tags for.
I have given it an attempt by looking at code examples I have seen via Google however I am getting the following error - Call to undefined method Infusionsoft\Infusionsoft::dsQuery()
Code:
<?php
//Connect to the Infusionsoft API
require_once 'vendor/autoload.php';
$infusionsoft = new \Infusionsoft\Infusionsoft(array(
'clientId' => 'key',
'clientSecret' => 'key',
));
// Fetch the required tags for this place
$getFields = array('Id','GroupDescription', 'GroupName');
$query = array('GroupName' => '%');
$tags = $infusionsoft->dsQuery("ContactGroup",1000,0,$query,$getFields);
var_dump($tags);
?>
First of all, there's no new API. Improvements are added to Infusionsoft API all the time, but it's still the same updated API. If you mean new Infusionsoft PHP SDK, then example request to get the tags looks this way:
$infusionsoft->data()->query('ContactGroup', $limit, $page, $queryData, $selectedFields, $orderBy, $ascending);
query() method is implemented in Infusionsoft/Api/DataService.php file
You connect to a specific Infusionsoft account during oAuth authorization flow. This basic flow is shown, for example, in PHP SDK examples
The error you see means exactly what it says - there's no such method dsQuery() in the updated SDK. The link to the SDK code where you can see all available methods was provided in the first point.

Google Play scraper

I'm trying to develop a Play Store reviews scraper in PHP and I need to make a POST request to this URL https://play.google.com/store/getreviews, and I saw the parameter post with firebug.
I am using Goutte library and here is my code:
require_once 'goutte.phar';
use Goutte\Client;
$client = new Client();
$params = Array(
"id" => "com.trello",
"pageNum" => 2 ,
"reviewSortOrder" => 2 ,
"reviewType" => 0,
"xhr" => 1
);
$crawler = $client->request('POST' , 'https://play.google.com/store/getreviews', $params);
The problem is that the request returns nothing. Is there anyone who already faced this problem and solved it?
I don't think this is possible. Google Play changed their review interface last year. They now have a "token" parameter which is missing here. I have worked before to try and work out what seeds this (see Google play review scraping changes) but I can't figure it out. After a number of attempts to hit that webservice with an incorrect request (presumably without the token) Google Play starts blocking your IP, that's why you'll be getting nothing back after a while (and won't be able to open Google Play in your browser either). If you find a solution, let me know!
This URL works for me, with the form-post data in your example.
https://play.google.com/store/getreviews?authuser=0

Categories