I'm trying to send batch notification from my app to several app users after runing the below code I get an error in the response:
"{"error":{"message":"(#100) Must specify a non-empty template `param","type":"OAuthException","code":100}}"`
Although the template param is set...
Appreciate any help on what am i doing wrong..
Here is the code I use:
$batched_request = array();
foreach ($users as $idx => $user) {
$request = array(
'method' => 'POST',
'relative_url' => '/' . $user['id'].'/notifications',
'access_token' => $app_access_token,
'template' => $template,
'href' => $href
);
$batched_request[] = json_encode($request);
}
$params = array('batch' => '[' . implode(',',$batched_request) . ']' );
try {
$response = $facebook->api('/','POST',$params);
} catch(FacebookApiException $e) {
error_log($e);
}
if you post via batch api, please have in mind, that you should enclose the template & href parameter as a http query string within the "body"-key.
for example:
$apiCalls[] = array(
"method" => "POST",
"relative_url" => $user['id'] . "/notifications",
"body" => http_build_query(array("href" => $href, "template" => $template, "ref" => "ref_key")),
"access_token" => $app_access_token
);
Related
In my wp project, I am using Assently for e-signature implementation. Though I have an account and created a pdf form file to be filled by the user I just am not able to proceed a bit. I am finding documentation not clear.
Also, I am not clear about what needs to be done so that the user will be shown form to process the transaction.
So, any help/suggestions to proceed forward is appreciated.
I have tried the following based on assently-laravel. But it's asking me to login. What is an error here?
Code:
define('ASSENTLY_DEBUG', true);
define('ASSENTLY_KEY', 'key');
define('ASSENTLY_SECRET', 'secret-generated');
include_once('assently/Assently.php');
$assently = new Assently();
$assently->authenticate(ASSENTLY_KEY, ASSENTLY_SECRET);
$url = 'https://test.assently.com/api/v2/createcasefromtemplate';
$default = array(
'Id' => '5a0e0869-' . rand(1111, 9999) . '-4b79-' . rand(1111, 9999) . '-466ea5cca5ce'
);
$data = array(
'auth' => $assently->auth(),
'templateId' => '0e004e2b-b192-4ce2-8f47-d7a4576d7df6',
'newCaseId' => '5a0e0869-' . rand(1111, 9999) . '-4b79-' . rand(1111, 9999) . '-466ea5cca5ce',
'agentUsername' => ''
);
$data = array(
'json' => $data
);
$options = array(
'http' => array(
'header' => "Content-type: application/json; charset=utf-8\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo '<pre>';
print_r($result);
die;
create this class inside assently folder
use Assently\AssentlyCase;
use Exception;
class CustomAssentlyCase extends AssentlyCase
{
public function createFromTemplate($data)
{
$default = [
'newCaseId' => '5a0e0869-'.rand(1111, 9999).'-4b79-'.rand(1111, 9999).'-466ea5cca5ce'
];
$json = array_merge($default, $data);
try{
$response = $this->client->post($this->url('createcasefromtemplate'), [
'auth' => $this->assently->auth(),
'json' => $json
]);
}catch(Exception $e){
print_r($e->getMessage());
}
return $response;
}
}
Use
define('ASSENTLY_DEBUG', true);
define('ASSENTLY_KEY', 'key');
define('ASSENTLY_SECRET', 'secret-generated');
include_once('assently/Assently.php');
include_once('assently/CustomAssentlyCase.php');
$assently = new Assently();
$assently->authenticate(ASSENTLY_KEY, ASSENTLY_SECRET);
$data = array(
'templateId' => '0e004e2b-b192-4ce2-8f47-d7a4576d7df6',
'newCaseId' => '5a0e0869-'.rand(1111, 9999).'-4b79-'.rand(1111, 9999).'-466ea5cca5ce',
'agentUsername' => 'agentUsername' // PUT your agent username here it is required
);
$customAssentlyCase = new CustomAssentlyCase($assently);
$result = $customAssentlyCase->createFromTemplate($data);
print_r($result);
Try this, though not tested but should work. Good luck.
Where did I make a mistake? My PHP-script:
<?php
// Set username and password
$lgname = "someUsername";
$lgpassword = "somePassword";
// First login to receive 1) token, 2) sessionid and 3) cookieprefix
$parameters = array('action' => 'login', 'lgname' => "$lgname", 'lgpassword' => "$lgpassword", 'format' => 'json');
options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($parameters)
),
);
$context = stream_context_create($options);
$result = file_get_contents("http://en.wikipedia.org/w/api.php", false, $context);
// Echo out the answer from MediaWiki-API
echo "$result";
// Put the needed parts of the answer into variables and echo them out
$array = json_decode($result,true);
$token = $array["login"]["token"];
$sessionid = $array["login"]["sessionid"];
$cookieprefix = $array["login"]["cookieprefix"];
echo "</BR>token: $token, sessionid: $sessionid, cookieprefix: $cookieprefix</BR>";
// Second login to 1) post token and 2) send sessionID within the header
$parameters = array('action' => 'login', 'lgname' => "$lgname", 'lgpassword' => "$lgpassword", 'lgtoken' => "$token", 'format' => 'json');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
"Cookie: " . $cookieprefix . "_session = $sessionid\r\n",
'method' => 'POST',
'content' => http_build_query($parameters)
),
);
$context = stream_context_create($options);
$result = file_get_contents("http://en.wikipedia.org/w/api.php", false, $context);
// Echo out result
echo "$result";
?>
What I get as an answer to my second POST-request is (exactly the same as to my first POST-request) that I need a token (even though I posted the token and even the sessionID in my second POST-request):
{"login": {
"result":"NeedToken",
"token":"82b3f2e1f1aa702ca6ceae473bb16bde",
"cookieprefix":"dewiki",
"sessionid":"531143bd7425722bf1be88e520dea6d5"}
}
The mistake is in using file_get_contents() in the first place. Use a PHP library for the MediaWiki web API, instead.
If you really want to do things yourself, ask a token from meta=tokens.
I am currently posting images URLs on different facebook pages but I am using many calls to do the same thing.
Instead of this, I am trying to work on a batch request to save on execution time but I have an issue.
Doing many calls, I use this:
$urlLink = '/' . $pageId . '/photos';
$args = array(
'url' => $this->image_url,
'message' => $this->message,
'published' => false,
'scheduled_publish_time' => strtotime($this->programmed_dt),
);
$res = $this->fb->api($urlLink, 'POST', $args);
It works fine.
With the batch request I tried with that:
$urlLink = '/' . $facebookPage['id'] . '/photos';
$args['access_token'] = $facebookPage['access_token'];
$queries[] = array('method' => 'POST',
'relative_url' => $urlLink,
'body' => $args,
'url' => $this->image_url
);
$res = $this->fb->api('?batch=' . json_encode($queries), 'POST');
The response I have is:
{"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}}
I tried to change the name field with all possibilities to send the image link, without success...
Any ideas for batch requests with image urls?
According to https://developers.facebook.com/docs/graph-api/making-multiple-requests/#multiple_methods I assume that your code which forms the request doesn't have the correct syntax.
From my point of view it should be the following:
$args['access_token'] = $facebookPage['access_token'];
$queries[] = array('method' => 'POST',
'relative_url' => $urlLink,
'body' => 'url=' . $this->image_url
);
$res = $this->fb->api('/?batch=' . json_encode($queries) . '&access_token=' . $args['access_token'], 'GET');
I can see everything ok in your code except this-
You should set upload support to true before posting image.
$this->fb->setFileUploadSupport(true);
for more detail you can check this answer:
CHECK HERE
This is the code from twilio api. Here 'callsid' is a query string.
$url = 'http://xxxx.com/phone/customer?to='.$number;
$call= $this->twilio->account->calls->get($this->request->query->get('CallSid'));
$call->update(array(
'Url' => $url,
'Method' => 'GET',
'StatusCallbackMethod' => 'GET',
'StatusCallback' => 'http://xxxx.com/phone/log/callback'
));
My question is that can we place an array key in the place of query string to fetch the key details? Like this:
$url = 'http://xxxx.com/phone/customer?to='.$number;
$call = $this->twilio->account->calls->get($this->request->query->get('url'));
$call->update(array(
'Url' => $url,
'Method' => 'GET',
'StatusCallbackMethod' => 'GET',
'StatusCallback' => 'http://xxxx.com/phone/log/callback'
));
Ricky from Twilio here.
If you want to filter by something other than CallSid with our PHP library you can use an iterator. For example this code will return calls that are currently in progress:
$filteredCalls = $client->account->calls->getIterator(
0, 50, array("Status" => "in-progress"));
foreach($filteredCalls as $call) {
print $call->price . '\n';
print $call->duration . '\n';
}
You can view a list of available filters in the docs.
Using the php graph api I want to add picture to an event. So I m looking for some examples for the new graph api !
I'm sorry if the question is a bit unclear. Creating an event facebook use standard pictures of 31
calendar icon of facebook
http://i.stack.imgur.com/w7tMp.png in monocolor and color
I ( and many other person ) want to replace this picture using php as you can do it via the facebook page.
All descriptions in the internet fail.
I use the following code
$name= $parameter['betreff'];
$beschreibung=$parameter['thema'];
start_time = $parameter['anfangsdatum'] . " " . $parameter['anfangszeit'];
$ort="" . $parameter['ort'];
$picture='http://www.tvwehen.de/facebook/facebook_plan_event/news.png';
$privacy="CLOSED";
$event_param = array(
'access_token' => $access_token,
'page_id' =>$fanPageId,
'name' => $name,
'start_time' => $start_time,
'description' => $beschreibung,
'location' => $ort,
'pic_big' => $picture,
'pic_small' => $picture,
'logo.png' => $picture,
'privacy' => $privacy
);
$event_id = $facebook->api($fanPageId . "/events", "POST", $event_param);
The event is created on the fanpage but without any picture ! Why ?
Your question is a bit unclear, but assuming I've understood you correctly, you simply want a users profile picture? That can be found here:
http://graph.facebook.com/username/picture
So mine would be at http://graph.facebook.com/filip.soderholm/picture
You may also use the userId instead of the username if you have that.
You can get help from this address: https://gist.github.com/1178154
<?php
/**
* Implementation of hook_nodeapi
*/
function hps_the_hook_nodeapi (&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($node->type == 'event') {
if ($op == 'insert') {
dpm($node);
//require_once(drupal_get_path('module', 'hps_the_hook') . '/lib/facebook-php-sdk/src/facebook.php');
$facebook = new Facebook(array(
'appId' => '193560340711521',
'secret' => 'secret',
'fileUpload' => true,
));
$page_id = "161330440592966";
$location = $node->field_location[0]['value'];
$from_date = $node->field_date[0]['value'];
$to_date = $node->field_date[0]['value2'];
$image_path = $node->field_image[0]['filepath'];
$event_param = array(
"access_token" => 'access_token',
"name" => $node->title,
"start_time" => strtotime($from_date),
"end_time" => strtotime($to_date),
"location" => $location,
"page_id" => $page_id,
"picture" => "#".realpath($image_path),
"source" => "#".realpath($image_path),
);
$facebook->setFileUploadSupport(true);
try {
dpm($event_param);
$event_id = $facebook->api("/161330440592966/events", "POST", $event_param);
dpm($event_id);
}
catch (Exception $ex) {
dpm($ex);
}
}
}
}
?>