I am using this code to subscribe the posted email.
<?
$api_key = "apikey";
$list_id = "listid";
$gotemail = $_POST['email'];
require('src/Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => $gotemail ) );
?>
Now, What should I do to check if there is any error, and if it is, block it from exiting the script (killing it and printing the error on screen)? Like just save it in a variable and use it later.
Thank you in advance!
Related
I have a working code that posts on twitter account via APi, using codebird. However, for some reason only the first account gets posted to, but not the second. No errors. Here's the php code:
function tweet($message) {
global $consumerkey, $consumersecret, $accesstoken, $accesssecret;
require_once('/home/curse/public_html/manage/twitter-php-sdk/src/codebird.php');
\Codebird\Codebird::setConsumerKey("$consumerkey", "$consumersecret");
$cb = \Codebird\Codebird::getInstance();
$cb->setToken("$accesstoken", "$accesssecret");
$params = array(
'status' => $message
);
$reply = $cb->statuses_update($params);
}
tweet("$twextra $makelink");
function tweet2($message) {
global $siimconsumerkey, $siimconsumersecret, $siimaccesstoken, $siimaccesssecret;
require_once('/home/curse/public_html/manage/twitter-php-sdk/src/codebird.php');
\Codebird\Codebird::setConsumerKey("$siimconsumerkey", "$siimconsumersecret");
$cb = \Codebird\Codebird::getInstance();
$cb->setToken("$siimaccesstoken", "$siimaccesssecret");
$params = array(
'status' => $message
);
$reply = $cb->statuses_update($params);
}
tweet2("$twextra $makelink");*
this seems pretty straightforward but i just can't get mailchimp to get the emails. I have a checkbox and all I want to do is say, if check then subscribe.
I get an error 500 and I have no idea where to go with this.
<?php echo CHtml::CheckBox('[subscribe]',true, array ( 'value'=>'yes',)); ?>
if ( $_POST['subscribe'])
{
Yii::import('application.vendors.mailchimp');
$mailchimp = new Mailchimp(Yii::app()->params['mailchimp']['key']);
$listId = '*******';
$email = array(
'email' => trim($_POST['User']['email']));
$subscriber = $mailchimp->list->subscribe(
$listId,
$email,
$merge_vars=null,
false,
false
);
}
I've followed this tutorial to implement mailchimp API v2.0 on my website.
It works great, however the double_optin option that I wanted to add and set to false (so that users don't need to validate their registration via e-mail) doesn't seem to be working. It's like if it was not taken into consideration at all, users still need to validate the registration via e-mail.
Is 'double_optin' => false placed at the wrong place? I had a look at mailchimp documentation but my level in programmation is not good enough to identify what is wrong.
Thanks for your help
<?php
$api_key = "12345486-us8";
$list_id = "123";
require('Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => htmlentities($_POST['email']),'double_optin' => false ) );
if ( ! empty( $subscriber['leid'] ) ) {
echo "success";
}
else
{
echo "fail";
}
?>
According to this (admittedly unofficial-looking) Mailchip_Lists documentation, you'll want to pass FALSE as the 5th parameter to subscribe().
Example:
$double_optin = FALSE;
$subscriber = $Mailchimp_Lists->subscribe(
$list_id,
array('email' => htmlentities($_POST['email'])),
NULL, // merge_vars
'html', // email_type
$double_optin
);
I am using facebook API to post comment on a post and the comment is posted successfully. But in response facebook returns:
An unexpected error has occurred. Please retry your request later.
When the I check the post, the comment is posted.
Here is my code sinppet:
$post_id = $_POST['post_id'];
$user_comment = $_POST['user_comment'];
$user_information = UserSocials::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
$access_token = $user_information->fb_access_token;
$app_id = 'xxx';
$app_secret = 'yyy';
Yii::import("application.extensions.facebooksdk.Facebook");
$config = array();
$config['appId'] = $app_id;
$config['secret'] = $app_secret;
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
$result=$facebook->api('/' . $post_id . '/comments', 'post', array(
'access_token' => $access_token,
'message' => 'Your message',
)
);
print_r($result);
I must get a success or failure response because I have to prompt the user that the comment was posted or not.
Can anyone tell where I am going wrong?
<?php
require './vendor/autoload.php';
$client = new Evernote\Client(array(
'consumerKey' => 'xxxx',
'consumerSecret' => 'xxxxx'
));
$requestToken = $client->getRequestToken('index.html');
$authorizeUrl = $client->getAuthorizeUrl($requestToken['oauth_token']);
$accessToken = $client->getAccessToken(
$requestToken['oauth_token'],
$requestToken['oauth_token_secret'],
$_GET['oauth_verifier']
);
$token = $accessToken['oauth_token'];
$client = EvernoteClient($token=$token);
$client = new Evernote\Client(array('token' => $token));
$noteStore=$client->getNoteStore();
$note = $Types->Note();
$note->title="I'm a test note!";
$note->content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">';
$note->content += '<en-note>Hello, world!</en-note>';
$note = $noteStore->createNote($note);
?>
I iam trying to login to user account and add note to there account.But i an not able to understand what is wrong.Can any one give code for my implementation .Thank you.
Not sure what error you got only from this code but Client->getRequestToken requires full callback URL (http://yourdomain/path) instead of just a file name.
You can see how it works here. Especially, function.php might help.