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);
Related
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,
)
));
I am currently doing a site on cakephp 2.6.2.
I use a plugin for comments, as follows: Comment plugin.
Everything works fine until I try to add a comment to a post, it then returns the following error:
Strict (2048): Declaration of Comment::afterSave() should be compatible with Model::afterSave($created, $options = Array)
[APP/Plugin/Comment/Model/Comment.php, line 2]
I do not understand why this error is raised and how I can resolve it.
I searched issues already covered but I do not understand what how I should proceed. I try several times but without success: s
I have in comment.php:
public function afterSave($created){
if ($created) {
$model = ClassRegistry::init($this->data[$this->alias]['ref']);
// Manual countercache, it's more flexible, no need to add complex relation on Comment Model
if($model->hasField('comment_count')){
$model->id = $this->data[$this->alias]['ref_id'];
$model->saveField('comment_count',$this->find('count',array(
'conditions' => array('ref'=>$this->data[$this->alias]['ref'],'ref_id'=>$this->data[$this->alias]['ref_id'])
)));
}
$this->getEventManager()->dispatch(new CakeEvent('Plugin.Comment.add', $this));
}
}
and CommentsController.php:
$this->Comment->create($this->request->data, true);
the changes I've tried to do:
$this->Comment->create($this->request->data, true);
to $this->Comment->create($this->request->data);
or $this->Comment->create(controller $this->request->data, true);
I'm sorry but i'dont understand what i exactly have to do :s
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);
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
I am having a tough time and have spent like 4 hrs trying to debug this. I am new to PHP, but did not expect this to be so hard.
This is the code, i am trying to update a contact table. i tried upsert and update nothign seems to work
this is the update" version of the code.
$id = '003A000000XRVFxIAP';
$updateFields = array (
'Id' => $id,
'MailingCity' => 'New York',
'MailingState' => 'NY'
);
$sObject1 = new SObject();
//$sObject1->fields = $updateFields;
//$sObject1->MailingCity= 'New York';
$sObject1->type = 'Contact';
try{
$updateResponse = $client->update(array($sObject1),'Contact');
$myID = $updateResponse->id;
}
Strict Standards: Creating default object from empty value in C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceEnterpriseClient.php on line 89 INVALID_FIELD: No such column 'fields' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. Error Info SoapFault exception: [sf:INVALID_FIELD] INVALID_FIELD: No such column 'fields' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. in C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceBaseClient.php:508 Stack trace: #0 C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceBaseClient.php(508): SoapClient->__call('update', Array) #1 C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceBaseClient.php(508): SoapClient->update(Object(stdClass))
#2 C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceEnterpriseClient.php(90): SforceBaseClient->_update(Object(stdClass))
#3 C:\xampp\htdocs\Proj1\createAccount.php(95): SforceEnterpriseClient->update(Array, 'Contact') #4 {main}
Looking at your trace you appear to be using the enterprise client and I can assume enterprise WSDL. This is strongly typed and you should be using the WSDL specific to your Salesforce org. If you are not using the WSDL downloaded from your org it will not have the correct objects and fields defined within it.
I would recommend using the partner client and partner WSDL. This is loosely typed and far more flexible. It would be easier to work with particularly if you aren't familiar with the PHP or the webservices.
The following should do your update...
$sObject1 = new stdClass();
$sObject1->type = 'Contact';
$sObject1->Id = $id;
$sObject1->fields['MailingCity'] = 'New York';
$sObject1->fields['MailingState'] = 'NY';
try
{
$updateResponse = $client->update( array( $sObject1 ) );
}
catch( Exception $exception )
{
// Do something
}
Note that the Id is a property of $sObject and not a value in the fields array. Also there is no need to specify the 'Contact' in your update call as you have it set in the type property of $sObject.
When using the Enterprise WSDL, don't create a new SObject, just create a new stdClass. See the examples in the PHP Getting Started Guide; SObjects are only for use with the partner WSDL.
I have encountered the same issue updating while using the Enterprise client. I experienced the same issue while updating a custom field on an Account object.
The issue that I had with the SObject was that it tried to update a parameter called 'fields' during the update. With the Enterprise WSDL not including that field, I used unset() to remove the 'fields' attribute from the SObject.
I appreciate this is a bit of a hacky solution, but it could come in useful for others that encounter this issue.
$sUpdateObject = new SObject();
$sUpdateObject->id = $record->Id;
$sUpdateObject->MyCustomField__c = 0;
unset($sUpdateObject->fields);
$updateResponse = $mySforceConnection->update(array($sUpdateObject), 'Account');
print_r($upsertResponse);