Mailchimp intergration error - php

We want to import all our database into one of your lists. We use php. The code is:
$api_key = "dXXXXXXX7eX276XXXXXXXX490";
$list_id = "7XXXb0XXXe";
$Mailchimp = new Mailchimp($api_key);
$Mailchimp_Lists = new Mailchimp_Lists($Mailchimp);
$batch = array();
$batch[] = array('email' => array(
'email' => 'xxxgmail.com',
"euid" => "xxx#gmail.com",
"leid" => "xxx#gmail.com"
),
'merge_vars' => array('FNAME' => 'XXX'));
$subscriber = $Mailchimp_Lists->batchSubscribe($list_id, $batch, false, true, true);
But I get an error
Mailchimp_User_DoesNotExist
Could not find user record with id
I tried many times, removed uuid and leid but no success. What is wrong? Thank you!

The API key used by me was incorrect.

Related

Zoom Api - I can't update a meeting

I am trying to update a meeting using Zoom API but I can't get it to work. I'm trying to do a PATCH request using eleague oauth2 client like this:
require '../vendor/autoload.php';
require_once '../config.php';
$id = $_POST['id'];
$topic = $_POST['topic'];
$type = $_POST['type'];
$start_time = $_POST['start_time'];
$duration = $_POST['duration'];
$agenda = $_POST['agenda'];
$params = array(
'topic' => $topic,
'type' => $type,
'start_time' => $start_time,
'duration' => $duration,
'agenda' => $agenda,
'password' => '123456'
);
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => CONEXAO_API['clientId'],
'clientSecret' => CONEXAO_API['clientSecret'],
'redirectUri' => CONEXAO_API['redirect_url'],
'urlAuthorize' => 'https://zoom.us/oauth/authorize',
'urlAccessToken' => 'https://zoom.us/oauth/token',
'urlResourceOwnerDetails' => 'https://api.zoom.us/v2/users/me'
]);
$options['body'] = json_encode( $params );
$options['headers']['Content-Type'] = 'application/json';
$options['headers']['Accept'] = 'application/json';
$request = $provider->getAuthenticatedRequest( 'PATCH',
'https://api.zoom.us/v2/meetings/'.$id,
unserialize($_SESSION['token']),
$options
);
$retorno = $provider->getParsedResponse($request);
var_dump($retorno);
I'm getting an empty response, and I'm not sure what is missing. Can anyone help me?
basically the response given by the api is blank or just meeting updated which isn't in json format. So in case you want to check whether its working go to zoom meeting panel and open the meeting which you are updating using api and run the api and check the meeting is updated in zoom meeting panel.
The problem is that the method getParsedResponse for some reason is not returning any message. But the script is working, it's updating the meeting the way it supposed to.
If I get the response using the method getResponse I can see the statusCode 204, which means that everything went ok.

Facebook Ads SDK - Unsupported Post Request

I got some example scripts from Facebook App Management to use the Marketing API. When I run the script, I just get this error by curl:
'Unsupported post request. Object with ID \'105101623679981\' does not exist, cannot be loaded due to missing permissions, or does not support this operation.
I already tried to deactivate the Sandbox Mode and go public, tried many different scripts in different languages and also other keys.
Any Ideas?
This is the Script:
<?php
//Add all those Uses and the autoloader
$access_token = '<my_very_long_accessToken';
$ad_account_id = '<my_account_id>'; //<-- This is the Object in the Error Code
$app_secret = '<my_app_secret>';
$page_id = '<my_page_id>';
$app_id = '<my_app_is>';
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
);
$params = array(
'objective' => 'PAGE_LIKES',
'status' => 'PAUSED',
'buying_type' => 'AUCTION',
'name' => 'My Campaign',
);
$campaign = (new AdAccount($ad_account_id))->createCampaign(
$fields,
$params
);
$campaign_id = $campaign->id;
echo 'campaign_id: ' . $campaign_id . "\n\n";
$fields = array(
);
$params = array(
'status' => 'PAUSED',
'targeting' => array('geo_locations' => array('countries' => array('US'))),
'daily_budget' => '1000',
'billing_event' => 'IMPRESSIONS',
'bid_amount' => '20',
'campaign_id' => $campaign_id,
'optimization_goal' => 'PAGE_LIKES',
'promoted_object' => array('page_id' => $page_id),
'name' => 'My AdSet',
);
//...
Yeah. I got it. It has to be "act_"
So bad. The Script is really crappy. So many Errors. And it's created by facebook!

Missing end time Google Calendar when insert event

I trying to insert an event in the Google Calendar. The authentication and to fetch events works without any problems. Unfortunately I got the following error message:
{
error: {
errors: [
{
domain: "global",
reason: "required",
message: "Missing end time."
}
],
code: 400,
message: "Missing end time."
}
}
I request the site with cURL in PHP. To count the Content-Length for the request I using the function countArrayChars(). The following is my code:
$start = date("c", strtotime($start));
$end = date("c", strtotime($end));
$data_array = array(
"end"=>array("dateTime"=>$end),
"start"=>array("dateTime"=>$start),
"summary"=>$name
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://www.googleapis.com/calendar/v3/calendars/primary/events',
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array("Content-length: ".countArrayChars($data_array),"Content-type: application/json","Authorization: Bearer $access_token\r\n"),
CURLOPT_POSTFIELDS => $data_array
));
$resp = curl_exec($curl);
curl_close($curl);
echo $resp;
function countArrayChars(array $array){
$charNumber = 0;
array_walk_recursive($array, function($val, $key) use (&$charNumber)
{
$charNumber += strlen($val) + strlen($key);
});
return $charNumber;
}
What I also tried is to set the data as a http_build_query, as well as a json_encode result. Unfortunately this also didn't work.
Thanks for every response.
UPDATE:
$data_array = array(
"end"=>array("dateTime"=>$end,"timeZone"=>"Europe/Zurich"),
"start"=>array("dateTime"=>$start,"timeZone"=>"Europe/Zurich"),
"summary"=>$name
);
UPDATE 2:
This is the output of $end
string(25) "2017-03-10T00:00:00+01:00"
I don't know if this will help you, but this is the code I use to add events to google calendar through the API:
$event = new Google_Service_Calendar_Event(array(
'summary' => $summary,
'location' => $location,
'description' => $description,
'start' => array(
'dateTime' => $startdatetime,
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => $enddatetime,
'timeZone' => 'America/Los_Angeles',
),
'reminders' => array(
'useDefault' => FALSE,
),
));
You usually need to add a timezone, like I have, which could be your problem. I would suggest trying that out first.
Update:
I can't find anything else that could be wrong with your code, it's probably something having to do with how Google accepts data. All I can offer you now is exactly how I do mine, which I know works:
First, follow the instructions here to setup service account, if not done already. Make sure to create a .p12 file, instead of JSON.
You can download the PHP Google Calendar File here as well, without needing to use composer.
Next, work with the code below to suit your needs, but this should work for you. (The dateTime was properly formatted before it was sent in POST, so you may need to change that)
header('Content-type: application/json');
require_once __DIR__ . '/google-api-php-client/src/Google/autoload.php';
$summary = $_POST["summary"];
$location = $_POST["location"];
$description = $_POST["description"];
$startdatetime = $_POST["startdatetime"];
$enddatetime = $_POST["enddatetime"];
$client_email = "clientemail"; //client email setup when you create the authorization in Google Developer Console.
$private_key = file_get_contents("privatekey.p12"); //location on your server where the .p12 file you created is stored
$scopes = array('https://www.googleapis.com/auth/calendar');
$user_to_impersonate = "primary"; //This can also be an email address associated with the current gmail login if you don't want to use the default one
$credentials = new Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key,
'notasecret', // Default P12 password
'http://oauth.net/grant_type/jwt/1.0/bearer', // Default grant type
$user_to_impersonate
); //Keep everything in this array the same
$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$event = new Google_Service_Calendar_Event(array(
'summary' => $summary,
'location' => $location,
'description' => $description,
'start' => array(
'dateTime' => $startdatetime,
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => $enddatetime,
'timeZone' => 'America/Los_Angeles',
),
'reminders' => array(
'useDefault' => FALSE,
),
));
$service = new Google_Service_Calendar($client);
$calendarId = $useremail;
$event = $service->events->insert($calendarId, $event);
echo json_encode($event);
Check that $start is less than $end.
the error of google is not correct.
you have to check al inputfield for strange symbols. I had Straße in locationfield...that gave the missing endtime error.
Hi the problem may be on special characters in the variable, must try to encode UTF-8.
please try this
'summary' => utf8_encode($summary),
'description' => utf8_encode($descripcion),
'location' => utf8_encode($location),
regards,
Luis

500 error when trying to add new order in TradeGecko API

Pretty specific problem, but I'll lay it out as best I can.
I can easily make a POST request to the TradeGecko API (detailed here: http://developer.tradegecko.com/) and get variant prices in return, that part of the interaction is working smoothly.
However, I'm trying to create a new order and I feel like I'm missing something!
Here's what I have:
<?php
$authorizeUrl = 'https://api.tradegecko.com/oauth/authorize';
$accessTokenUrl = 'https://api.tradegecko.com/oauth/token';
$clientId = <MY_CLIENT_ID>;
$clientSecret = <MY_CLIENT_SECRET>;
$redirectUrl = <REDIRECT_URI>;
// https://github.com/adoy/PHP-OAuth2
require("Client.php");
require("GrantType/IGrantType.php");
require("GrantType/AuthorizationCode.php");
$client = new OAuth2\Client($clientId, $clientSecret, OAuth2\Client::AUTH_TYPE_AUTHORIZATION_BASIC);
$client->setCurlOption(CURLOPT_USERAGENT,$userAgent);
$client->setAccessToken(<MY_ACCESS_TOKEN>);
$client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_BEARER);
$params =
array('order' =>
array(
'company_id' => '12345',
'shipping_address_id' => 1,
'billing_address_id' => 1,
'status' => 'active',
'issued_at' => '10-04-2016',
'order_line_items' => array(
array('variant_id' => 123456,
'quantity' => 2),
array('variant_id' => 123457,
'quantity' => 2)
)
)
);
$response = $client->fetch('https://api.tradegecko.com/orders', false, $params);
print_r($response);
?>
I'm hoping that there's something in that code that someone else might spot, I've been staring at it for the better part of 6 hours now, and I can't figure out why this won't go through.

zend google fusion table update

As anyone any idea on how to update a table in google fusion using Zend framework?
I can get the data:
$url = "https://www.google.com/fusiontables/api/query?sql=SELECT%20name%20FROM%201695591";
$data = $gdata->get($url);
$postcodes = $data->getRawBody();
But have no idea how to update a row ...
I know I have to 'call' this url, but no idea how :
UPDATE table_id
SET column_name = value {, column_name = value }*
WHERE ROWID = row_id
Thank you
Try this class http://barahlo.semero.com/description/Zend_Gdata_Fusion.zip
Example of usage:
$client = Zend_Gdata_ClientLogin::getHttpClient('your_login_here#gmail.com', 'your_pass_here', 'fusiontables');
$base = new Zend_Gdata_Fusion($client);
$sql = "SELECT ROWID FROM 596524 WHERE id = 1;";
$rowdata = $base->query($sql)->get_array();
print_r($rowdata);
$newRowId = $base->insertRow('596524',array(
'id' => time(),
'name' => 'trird row',
'added' => date('n/j/y'),
) );
$base->updateRow(
'596524',
array('name' => 'new first row'),
$rowdata[1][0] //ROWID from insert query
);
Oauth login for Zend_Gdata:
$oauthOptions = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '1.0',
'signatureMethod' => 'HMAC-SHA1',
'consumerKey' => $CONSUMER_KEY,
'consumerSecret' => $CONSUMER_SECRET
);
$consumer = new Zend_Oauth_Consumer($oauthOptions);
$token = new Zend_Oauth_Token_Access();
$client = $token->getHttpClient($oauthOptions,null);
$base = new Zend_Gdata_Fusion($client);
// ...
Also, there is official php client library http://code.google.com/p/fusion-tables-client-php/

Categories