Google+ API CommentActivity return 400 Error - php

I'm having no luck calling the Google+ API for pushing a CommentActivity moment.
I have been able to push an AddActivity successfully as well as a DiscoverActivity.
I read somewhere on the internet whilst searching for a solution that the 400 HTTP Status represents that my user credentials are invalid, but I have been able to post AddActivity & DiscoverActivity after trying CommentActivity and I have tried disconnecting and reconnecting my account and linking the required credentials to no avail.
Here's my code to generate the moment, I believe this is the error, and it's probably something to do with the use of a Target and a Result in this moment type (Neither DiscoverActivity nor AddActivity have a Result field). In particular, the Target's and Result's URLs are the same but the Result's has an appended anchor. The documentation implies that this should work fine, however.
$moment = new Google_Moment();
$moment->setType("http://schemas.google.com/CommentActivity");
$target = new Google_ItemScope();
$target->setUrl(get_permalink($comment->comment_post_id));
$target->setType("http://schema.org/Article");
$moment->setTarget($target);
$result = new Google_ItemScope();
$result->setId("comment-".$comment_id);
$result->setType("http://schema.org/Comment");
$result->setUrl(get_comment_link($comment_id));
$result->setText($comment->comment_content);
$moment->setResult($result);
Soci_Base::getSocial("google")->getUser($user)->GPlus->moments->insert('me', 'vault', $moment);
GPlus is a reference to a Google_PlusService object.
Here's my exception I receive with stack trace (Pointless parts of the files are omitted, hooks.php and plugin.php are not the Google+ API)
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/plus/v1/people/me/moments/vault?key=AIzaSyBa27u5PtBgFHO4SY_Fq9_0sO39pFWrRzE: (400) Invalid Value' in /~/src/io/Google_REST.php:66 Stack trace:
#0 /~/G+/src/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest))
#1 /~/G+/src/service/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest))
#2 /~/G+/src/contrib/Google_PlusService.php(167): Google_ServiceResource->__call('insert', Array)
#3 /~/hooks.php(54): Google_MomentsServiceResource->insert('me', 'vault', Object(Google_Moment))
#4 /~/plugin.php(406): soci_comment('108040')
#5 /~ in /~/lib/G+/src/io/Google_REST.php on line 66
I think that's all of the info I have on the matter - I have no idea to get the exact HTTP request the script makes.
Thank you in advance for any and all help and for even having a look ^_^
Here's the code for the whole login sequence:
Soci_Google::addActionRequirement('http://schemas.google.com/AddActivity');
Soci_Google::addActionRequirement('http://schemas.google.com/CommentActivity');
Soci_Google::addActionRequirement('http://schemas.google.com/CreateActivity');
Soci_Google::addActionRequirement('http://schemas.google.com/DiscoverActivity');
Soci_Google::addActionRequirement:
public static function addActionRequirement($url) {
self::$activities[] = $url;
}
self::$token is just a reference to a string
$ret = new Soci_Google();
self::$users[$id] = $ret;
$ret->setToken(self::$meta->getMeta($user, self::$token));
return $ret;
Soci_Google __construct():
public function __construct() {
$this->googleObj = new Google_Client();
$this->googleObj->setApplicationName(self::$appName);
$this->googleObj->setClientId(self::$clientID);
$this->googleObj->setClientSecret(self::$clientSecret);
$this->googleObj->setRedirectUri(self::$redirectURI);
$this->googleObj->setDeveloperKey(self::$devKey);
$this->GPlus = new Google_PlusService($this->googleObj);
$this->googleObj->setRequestVisibleActions(self::$activities);
}
Soci_Goolge setToken
$this->googleObj->setAccessToken($googleUsrToken);

Related

Cannot retrieve Stripe data on success page

I have followed the Stripe documentation, trying to get the e-mail address of a customer but it fails with the following error:
PHP Fatal error: Uncaught exception 'Stripe\Exception\InvalidArgumentException'
with message 'The resource ID cannot be null or whitespace.' in /home/phuketto/public_html/stripe-php/lib/Service/AbstractService.php:99
Stack trace:
#0 /home/phuketto/public_html/stripe-php/lib/Service/Checkout/SessionService.php(90): Stripe\Service\AbstractService->buildPath('/v1/checkout/se...', NULL)
#1 /home/phuketto/public_html/ipnstripe.php(9): Stripe\Service\Checkout\SessionService->retrieve(NULL)
#2 {main}
thrown in /home/phuketto/public_html/stripe-php/lib/Service/AbstractService.php on line 99
In my create session script I am using:
'success_url' => 'https://www.example.com/ipnstripe.php?session_id={CHECKOUT_SESSION_ID}',
In my success_url I am trying to get the customer e-mail to be used further down the script but something goes wrong and the rest of the script is not executed:
require_once('./stripe-php/init.php');
$stripe = new \Stripe\StripeClient('sk_live_xxxxx');
$session = $stripe->checkout->sessions->retrieve($_GET['session_id']);
$customer = $stripe->customers->retrieve($session->customer);
$payeremail = $customer->email;

Trouble understanding Facebook Uncaught Exception

I'm super new to Facebook PHP SDK. I am having trouble understanding the stack trace below; where should I look for the error?
The Facebook Scheduled posts are successfully processing, however, this error causes a bad user experience, but, everything else in my program is working fine. It looks like it may be trying to process something that isn't there.
The last line of code being executed (I know because the scheduled posts show up in my Facebook Test Account) is:
$responses = $fb->sendBatchRequest(($batch), $this->session->userdata('fb_access_token'));
$batch is defined as:
foreach($esdarr as $key => $event_start_datetime){$sched_time = strtotime($event_start_datetime)- 18000;
$event_end_datetime = $eedarr[$key];
$requestScheduleEvent = $fb->post('/'.$band_page_id.'/feed', ['message' => $band_name.' is playing today at '.$venue_name.' '.date('(l), g:ia', strtotime($event_start_datetime)), 'published'=>false, 'scheduled_publish_time'=>$sched_time], $pageToken);
$batch[$key]=$requestScheduleEvent;
}
This is all within a CI Controller (event.php) with public function add(). Then I get this error:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Argument for add() must be of type array or FacebookRequest.' in /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php:85 Stack trace:
#0 /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php(78): Facebook\FacebookBatchRequest->add(Object(Facebook\FacebookResponse), 0)
#1 /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php(61): Facebook\FacebookBatchRequest->add(Array)
#2 /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/Facebook.php(492): Facebook\FacebookBatchRequest->__construct(Object(Facebook\FacebookApp), Array, 'EAAYzEGW0ZAsoBA...', 'v2.7')
#3 /home/my_user/public_html/development/application/controllers/user/event.php(777): Facebook\Facebook->sendBatchRequest(Array, 'EAAYzEGW0ZAsoBA...')
#4 [internal function]: Event->add in /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php on line 85
If I change line #85 of FacebookBatchRequest.php as follows (that is; redirect the page to the correct URL within the CI structure), everything seems to work fine:
public function add($request, $name = null)
{
if (is_array($request)) {
foreach ($request as $key => $req) {
$this->add($req, $key);
}
return $this;
}
if (!$request instanceof FacebookRequest) {
***redirect('user/event');***
throw new \InvalidArgumentException('Argument for add() must be of type array or FacebookRequest.');
}
$this->addFallbackDefaults($request);
$requestToAdd = [
'name' => $name,
'request' => $request,
];
Of course, this is a tenuous workaround at best. So, I'd like to know why the error is being thrown in the first place.
If you defined add() in your program and add() is also built in to the SDK, it won't work. Try using a different name.
If that isn't the problem, can you please post your code? Perhaps one of us can find it.
What language are you using? Perhaps you just have a syntax error.
I hope this helps in any way!
Okay, this ended up being an erroneous use of the batch process on my part.
$requestScheduleEvent = $fb->post('/'.$band_page_id.'/feed', ['message' => $band_name.' is playing today at '.$venue_name.' '.date('(l), g:ia', strtotime($event_start_datetime)), 'published'=>false, 'scheduled_publish_time'=>$sched_time], $pageToken);
Needed to use the request method:
$batch[$key] = $fb->request('POST', '/'.$band_page_id.'/feed', ['message' => $band_name.' is playing today at '.$venue_name.' '.date('(l), g:ia', strtotime($event_start_datetime)), 'published'=>false, 'scheduled_publish_time'=>$sched_time], $pageToken);

PHP: Error in creating Server Instance in Google Cloud Compute

While using Google Cloud Compute's API in PHP, I am able to start, stop, delete instances as well as create and delete disks.
However, when trying to create an Instance, I keep getting this error
Invalid value for field 'resource.disks'
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/compute/v1/projects/project/zones/zone/instances: (400) Invalid value for field 'resource.disks': ''. Boot disk must be specified.' in /var/www/html/google/google-api-php-client/src/Google/Http/REST
Here is the request I am making
self::connectClient();
$computeService = new Google_Service_Compute($this->client);
if ($this->client->getAccessToken())
{
$googleNetworkInterfaceObj = new Google_Service_Compute_NetworkInterface();
$network = self::DEFAULT_NETWORK;
$googleNetworkInterfaceObj->setNetwork($network);
$diskObj = self::getDisk($instance_name);
$new_instance = new Google_Service_Compute_Instance();
$new_instance->setName($instance_name);
$new_instance->setMachineType(self::DEFAULT_MACHINE_TYPE);
$new_instance->setNetworkInterfaces(array($googleNetworkInterfaceObj));
$new_instance->setDisks(array(
"source"=>$diskObj->selfLink,
"boot"=>true,
"type"=>"PERSISTENT",
"deviceName"=>$diskObj->name,
));
$insertInstance = $computeService->instances->insert(self::DEFAULT_PROJECT,self::DEFAULT_ZONE_NAME, $new_instance);
Any help will be highly appreciated, thank you.
Ok the solution was really simple (and silly)
Instead of
$new_instance->setDisks(array(
"source"=>$diskObj->selfLink,
"boot"=>true,
"type"=>"PERSISTENT",
"deviceName"=>$diskObj->name,
));
It's supposed to be
$new_instance->setDisks(array(
array(
'source'=>self::getDisk($instance_name)->selfLink,
'boot'=>true,
'type' => "PERSISTENT",
'deviceName'=>self::getDisk($instance_name)->name,
)
));

Magento Payment Failure at function callDoDirectPayment()

I am having trouble debugging the payment gateway on Magento 1.6.1 using Paypal Payments Pro. It keeps failing with the message 'There was an error processing your order. Please contact us or try again later".
I have tried examining the error logs, and have posted the results below. First time using this system and more of a front end dev but I'm managing to kind of follow along with the php.
The key line where it appears to fail is
$this->_importFromResponse($this->_doDirectPaymentResponse, $response);
Could someone explain exactly what this line does? What a sensible next step in investigating this process should be? Any additional paypal / magento specific knowledge more than welcome!
I'm guessing that since the array is created then it could be a problem transferring to paypal (my api signature should be okay - the express gateway works)- how would I go about confirming or rebuking this hypothesis?
Thanks
(first 8 lines of the var/exception.log- with the referenced code snippets, and also some extra content from the var/system.log produced by the Mage::log() functions.)
exception 'Mage_Core_Exception' with message 'There was an error processing your order.
Please contact us or try again later.' in /var/www/magento/app/Mage.php:563
Stack trace:
#0 /var/www/magento/app/code/core/Mage/Paypal/Model/Api/Nvp.php(974):
Mage::throwException('There was an er...')
if (!$this->_validateResponse($methodName, $response)) {
Mage::logException(new Exception(
Mage::helper('paypal')->__("PayPal response hasn't required fields.")
));
Mage::throwException(Mage::helper('paypal')->__('There was an error processing
your order.
Please contact us or try again later.'));
}
#1 /var/www/magento/app/code/core/Mage/Paypal/Model/Api/Nvp.php(648):
Mage_Paypal_Model_Api_Nvp->call('DoDirectPayment', Array)
public function callDoDirectPayment()
{
Mage::log("hello world");
// 2013-03-20T00:04:50+00:00 DEBUG (7): hello world
$request = $this->_exportToRequest($this->_doDirectPaymentRequest);
Mage::log($request);
// 2013-03-20T00:04:50+00:00 DEBUG (7): Array
$this->_exportLineItems($request);
if ($this->getAddress()) {
$request = $this->_importAddresses($request);
}
$response = $this->call(self::DO_DIRECT_PAYMENT, $request);
Mage::log($response);
(
[PAYMENTACTION] => Authorization
[IPADDRESS] => 81.98.95.116
[RETURNFMFDETAILS] => 1
[AMT] => 0.50
[CURRENCYCODE] => GBP
[INVNUM] => 100000063
[NOTIFYURL] => http://www.store.com/paypal/ipn/
[EMAIL] => hello#email
[CREDITCAR] => xxxxxxxxxxxxxx
[EXPDATE] => xxxxxx
[CVV2] => XXX
[ISSUENUMBER] =>
)
$this->_importFromResponse($this->_doDirectPaymentResponse, $response);
Mage::log("nothing to see here")
// This returns nothing to the system.log and so I assume is the point of failure
}
#2 /var/www/magento/app/code/core/Mage/Paypal/Model/Direct.php(343):
Mage_Paypal_Model_Api_Nvp->callDoDirectPayment()
// call api and import transaction and other payment information
/**
* Place an order with authorization or capture action
*
* #param Mage_Sales_Model_Order_Payment $payment
* #param float $amount
* #return Mage_Paypal_Model_Direct
*/
protected function _placeOrder(Mage_Sales_Model_Order_Payment $payment, $amount)
{ //...........(343)
$api->callDoDirectPayment();
$this->_importResultToPayment($api, $payment);
try {
$api->callGetTransactionDetails();
} catch (Mage_Core_Exception $e) {
// if we recieve errors, but DoDirectPayment response is Success, then set
Pending status for transaction
$payment->setIsTransactionPending(true);
}
(343)
$this->_importResultToPayment($api, $payment);
return $this;
}
#3 /var/www/magento/app/code/core/Mage/Paypal/Model/Direct.php(178):
Mage_Paypal_Model_Direct->_placeOrder(Object(Mage_Sales_Model_Order_Payment), 45)
#4 /var/www/magento/app/code/core/Mage/Sales/Model/Order/Payment.php(1026):
Mage_Paypal_Model_Direct->authorize(Object(Mage_Sales_Model_Order_Payment), 45)
#5 /var/www/magento/app/code/core/Mage/Sales/Model/Order/Payment.php(311):
Mage_Sales_Model_Order_Payment->_authorize(true, 45)
#6 /var/www/magento/app/code/core/Mage/Sales/Model/Order.php(855):
Mage_Sales_Model_Order_Payment->place()
#7 /var/www/magento/app/code/core/Mage/Sales/Model/Order.php(1073):
Mage_Sales_Model_Order->_placePayment()
#8 [internal function]: Mage_Sales_Model_Order->place()
Do you have debugging enabled in your PayPal settings in Magento? If so, then you should see a log show up in /var/log so you can see the RAW request and response data that was sent back and forth.
This will allow you to see the actual error code and message that came back in the response which will help you figure out what exactly went wrong.

SugarCRM: Unable to create Calls/Meetings - PHP Catchable fatal error with TimeDate::_getUserTZ()

Helllo,
Recently I upgraded to 6.2 GA from 6.1.4 via the upgrade patch.
Even since then I'm unable to create anything that has direct relation with Date & Time, namely, Call Logs, Meetings and Tasks.
When I do the same using a subpanel, the entry simply vanishes and is NEVER created.
When I try from one of the respective modules under Activities, I get a HTTP 500 error upon submission.
The Apache error log reveals the following:
PHP Catchable fatal error: Argument 1 passed to TimeDate::_getUserTZ() must be
an instance of User, boolean given, called in /home/crm/include/TimeDate.php on
line 849 and defined in /home/crm/include/TimeDate.php on line 259, referer:
http://mysite/index.php?module=Leads&offset=1&stamp=1307694072083825200&return_module=Leads&action=DetailView&record=xxxxxxxxxxxx
Unfortunately, this has happened to a production server and I noticed this problem only too late.
How can I fix this? Seeking your help urgently.
Thanks,
m^e
UPDATE 1
I've managed to apply a temporary patch to this and got it working...
Line 849 of TimeDate.php is part of a function that looks like:
function to_display_date_time($date, $meridiem = true, $convert_tz = true, $user = null)
{
return $this->_convert($date,
self::DB_DATETIME_FORMAT, self::$gmtTimezone, $this->get_date_time_format($user),
$convert_tz ? $this->_getUserTZ($user) : self::$gmtTimezone, true);
}
This function is in turn calling another one _getUserTZ() to which it is supposed to pass a variable of the type User. Instead it is passing null.
I used a snippet to check for empty $user and assign a value to it if needed. The code is part of another function named _getUser() found in this same file....
protected function _getUser(User $user = null)
{
if (empty($user)) {
$user = $this->user;
}
if (empty($user)) {
$user = $GLOBALS['current_user'];
}
return $user;
}
I borrowed the code from this function and pasted it inside to_display_date_time(), making it look like:
function to_display_date_time($date, $meridiem = true, $convert_tz = true, $user = null)
{
if (empty($user)) {
$user = $this->user;
}
if (empty($user)) {
$user = $GLOBALS['current_user'];
}
return $this->_convert($date,
self::DB_DATETIME_FORMAT, self::$gmtTimezone, $this->get_date_time_format($user),
$convert_tz ? $this->_getUserTZ($user) : self::$gmtTimezone, true);
}
Now Calls / Meetings are working again.. but I still wonder what's the actual fix to this issue. My way should prove to be a quick fix for anyone who needs to rectify this in a hurry.
If anyone can get to the root of the problem and a more elegant fix, I'm willing to offer a bounty.
Cheers,
m^e

Categories