this is my first question to stackoverflow, so if's something wrong please advise..
Well the problem is Facebook real time updates :
I have successfully created subscription to page and it's admin user ( test page and test app created ), user has agreed permissions to manage_page, read_stream, read_friendlist, read_insights,publish_actions and a lot of user's data ( about,email etc etc )
When i query GET to Graph api with edge /subscriptions i get the result :
{
"data": [
{
"object": "user",
"callback_url": "LIVE_CALLBACK_URL",
"fields": [
"feed"
],
"active": true
},
{
"object": "page",
"callback_url": "LIVE_CALLBACK_URL",
"fields": [
"built",
"description",
"email",
"feed",
"location",
"name",
"personal_info",
"written_by"
],
"active": true
}
]
}
So, that's taken care of, after that i searched why Facebook isn't sending me any updates ( which I log to somefile.txt ) So i found out you need to query the Graph api with /tabs to create page tab for my api. When i query that it returned "success" so that's created ( can't find out where it's stored, but it working ... ).
After that i have created some data on my profile, to test and also on the page to see if the Facebook is sending any updates, and it's suddenly send one update that was comment on my user profile post ( shared on timeline ).
The response was :
14:17 05.02.2015
Array
(
[object] => user
[entry] => Array
(
[0] => Array
(
[uid] => ****my_fb_id****
[id] => ****my_fb_id - not_someone_else****
[time] => 1423146339
[changed_fields] => Array
(
[0] => feed
)
)
)
)
So Facebook send's the empty feed, and it's ok, probably some permissions or something else, but after that i have made more posts and ppl commented on it ( on user profile and test page ) but Facebook didn't send any updates, or any call to my web page.
So has anyone facing this problem in the past, and how he solved that ?
The part that is for receiving the update from Facebook is :
$method = $_SERVER['REQUEST_METHOD'];
if(isset($_GET['hub_mode']) && isset($_GET['hub_verify_token'])){
if (trim($method) == 'GET' && trim($_GET['hub_mode']) == 'subscribe' && trim($_GET['hub_verify_token']) == VERIFY_TOKEN) {
print $_GET['hub_challenge'];
}
}
else if ($method == 'POST') {
$updates = json_decode(file_get_contents("php://input"), true);
$file = 'log.txt';
$current = file_get_contents($file);
#$results = print_r($updates,true);
$current .= $results;
file_put_contents($file, $current);
}
I have tried to detail my problem as much i as could... Searched but don't really understand why it's not working.
Apart from using an outdated method as #CBroe outlined, I think you have a misunderstanding: Facebook will not send you the data that has changed, but the object (and it's fields/edges) the change occurred for User object changes.
For Pages, you can receive the changes itself (changed_fields vs. changes fields in the FB request).
See
https://developers.facebook.com/docs/graph-api/real-time-updates/v2.2#receiveupdates
Once a subscription is successfully created, Facebook will make an HTTP POST request to your callback URL every time that there are changes (to the chosen fields or edges).
That means you need to contruct a separate request from the info object you get from Facebook. In your example it would be a request to your user's feed
GET /{user_id}/feed
to query for recent changes.
Related
There is currently 25k+ users we have in database. All users are subscribed to a common topic All.
I have two directories inside public_html. First is for API built in codeigniter. This API is used to provide data for all adnroid and iOS devices.
Second directory is for admin panel built in Laravel. We use it to upload data and also to send notification to firebase topics.
Both API and Admin Panel share same database.
If we send notification to topics which is not subscribed by much
users, there is no issue. But If I send notificaiton to a topic
which has much users It causes problems on our backend. The API
stops responding, or sometimes takes too long to respond.
Sometimes also admin panel stops responding too.
I am so confused because all the things are handled by firebase. I just make one API call.
Can anyone explain what's causing the problem?
Or any possible reason?
Update
use Kreait\Firebase\Messaging;
use Illuminate/Support/Http/Request;
trait UserTrait {
public function notify(Request $request, Messaging $messaging) {
$message_hi = array(
"notification_type" => $notification_type,
"notification_title" => $notification_title_hi,
"icon_image" => $icon_image,
"notification_description" => $request->notificationText_hi,
"image_url" => $request->image_url,
);
$message = array(
"notification_type" => $notification_type,
"notification_title" => $notification_title,
"icon_image" => $icon_image,
"notification_description" => $request->notificationText,
"image_url" => $request->image_url,
);
$commodityIdArray = $request->cId
//to send all
if($request->notification_type == 1) {
$messaging->sendAll([
['topic' => 'All', 'data' => $message],
['topic' => 'All_hi', 'data' => $message_hi],
]);
} else {
//to send to a fourite topic subscribed by some users
//Prepare Condition for both hindi and english users
$topic_condition = "";
$topic_condition_hi = "";
foreach($commodityIdArray as $topic) {
$topic_condition .="'".$topic."' in topics && ";
$topic_condition_hi.="'".$topic."_hi' in topics &&";
}
//send notification to hindi and english topics
$messaging->sendAll([
['condition' => substr($topic_condition, 0, -3), 'data' =>
$message],
['condition' => substr($topic_condition_hi, 0, -3), 'data' =>
$message_hi],
]);
}
}
Use Queue
You have to use a Queue which set your process in queue and when one process completes, the second one starts
you can also set number of retries of your process
So I am using an API (SendInBlue - a transactional email service) and I am trying to use the API to display a list of the users on my webpage.
Below, SendInBlue has given me sample code to use, however when I put them together I just get a blank screen.
I know this is a total beginner question... but how do I put these 2 pieces of code together so that it actually displays the list of contacts on my website?
Thank you so much!!
EXAMPLE
require('../mailin.php');
$mailin = new Mailin("https://api.sendinblue.com/v2.0","your access key");
$data = array( "listids" => array(1,2),
"timestamp" =>"2015-05-22 14:30:00",
"page" => 1,
"page_limit" => 2
);
var_dump($mailin->display_list_users($data));
SAMPLE OUTPUT
{
"code":"success",
"message":"Retrieved details of all users for the given lists",
"data":{
"data":[
{
"blacklisted":0,
"email":"email1#domain.com",
"id":1,
"listid":[1],
"blacklisted_sms":1,
"last_modified" : "2015-05-22 15:30:00"
},
{
"blacklisted":1,
"email":"email2#domain.com",
"id":2,
"listid":[1,2],
"blacklisted_sms":0 ,
"last_modified" : "2015-05-25 19:10:30"
}
],
"page":1,
"page_limit":2,
"total_list_records":100
}
}
Ok I figured this out. I turned every attribute into a variable like so...
$subscriberemail = $getemails['data']['data'][$number]['email'];
This took ages to figure out!
I'm using facebook PHP SDK , facebook api version 2.2.
I want to display the user news feed. I'm using the following api get this.
$facebookConncetion->api("$oauthUserId/home",
'GET',
array("access_token" => $accessToken,
"limit" => '15',
"comments.limit" => 10,
"likes.limit" => 10
)
);
But it returns all the post in the user home page with 10 comment and 10 likes and it does not return summary of like and comment. How can I format this api to get the like and comment summary per post?
You have to add .summary(true) and .filter(stream) to the like and comment request just like you added the limit.
Summary will return something like this:
"comments" : {
"data" : [ ARRAY OF COMMENTS ] },
"paging" : { PAGING CURSORS/URLS }.
"summary" : {
"total_count" : NUMBER OF COMMENTS
}
},
Adding .filter(stream) will return ALL comments/likes. With out this there may be some missing due to Facebook filtering them out due to their low "story" value. It will also order all comments/likes in true chronological order.
https://developers.facebook.com/docs/graph-api/reference/v2.2/object/comments
Look under "Modifiers" works with both comments and likes.
I am currently working on a submit order API for OpenCart. The purpose of this API is not for the webpage part of OpenCart, but for our mobile app to interact with OpenCart.
From my research, there appears to be two ways to submit an order:
Method One:
On the OpenCart webpage, when you want to physically want to submit an order, you go through the workflow of:
add product to shopping cart through checkout/cart/add
input payment_address through checkout/payment_address/validate
input shipping_address through checkout/shipping_address/validate
input shipping method through checkout/shipping_method/validate
input payment method through checkout/payment_method/validate
Confirm/submit the order through (I don't know what URL is actually requested to submit an order).
It appears the benefit of this method is that, given the condition that the customer is logged in, AND you have an API to add items to cart, you don't need to go through the step of manually adding products to cart in the URL. You can also use a string such as existing in payment_address and shipping_address to denote an existing address (so you don't need to manually input anything at all in the URL).
Method Two:
Using checkout/manual. This method, however, requires fully manually setting the inputs for everything:
store_id
customer_id
customer_group_id
payment_country_id
payment_zone_id
payment_country_id
order_product[]
order_voucher
shipping_method[]
order_total[contains keys such as code, title, text, value, and sort_order]
payment[]
May have missed something..
The use of checkout/manual seems to be the API that is for our needs, and I especially like that it would return warning/error messages if the request is not successful - however, the first method allows the the customer to have an interface to add products to cart and access existing variables such as shipping_address, payment_address, and more, given the condition that they're logged in (I'm aware that there is code that does cart->clear() and customer->logout() if the user is logged in).
My question is - has anyone ever implemented manually checking out before? How did you implement it?
Update:
Currently writing a script that would POST some dummy inputs to checkout/manual:
public function submit()
{
# Our new data
$data = array(
"store_id" => 0,
"customer" => "My Name",
"customer_id" => 1,
"customer_group_id" => 1,
"payment_country_id" => 223,
"payment_zone_id" => 3663,
"order_product[0][product_id]" => 1791,
"order_product[0][quantity]" => 1,
"order_product[0][price]" => 5.01,
"order_total[0][code]" => "sub_total",
"order_total[0][title]" => "Sub-Total",
"order_total[0][text]" => "$5.01",
"order_total[0][value]" => 5.01,
"order_total[0][sort_order]" => 1,
"order_total[1][code]" => "total",
"order_total[1][title]" => "Total",
"order_total[1][text]" => "$5.01",
"order_total[1][value]" => 5.01,
"order_total[1][sort_order]" => 9,
"payment_firstname" => "My",
"payment_lastname" => "Name",
"payment_company" => "SomeCompany",
"payment_address_1" => "#123 1234 NameOf street",
"payment_address_2" => "",
"payment_postcode" => "12345",
"payment_city" => "New York",
"shipping_firstname" => "My",
"shipping_lastname" => "Name",
"shipping_company" => "SomeCompany",
"shipping_address_1" => "#123 1234 NameOf street",
"shipping_address_2" => "",
"shipping_postcode" => "12345",
"shipping_city" => "New York",
"shipping" => "free.free",
"shipping_method" => "Free Shipping",
"shipping_code" => "free.free",
"shipping_country_id" => 223,
"shipping_zone_id" => 3663,
"payment" => "cod",
"payment_method" => "Cash On Delivery",
"payment_code" => "cod",
"order_status_id" => 1
);
# Create a connection
$url = HTTP_SERVER . 'index.php?route=checkout/manual';
$ch = curl_init($url);
# Form data string
$postString = http_build_query($data, '', '&');
# Setting our options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Get the response
$response = curl_exec($ch);
echo $response;
curl_close($ch);
}
However, the return data is this:
{"error":{"warning":"You do not have permission to access this page, please refer to your system administrator."}}
Update 2:
The error was thrown since I could not satisfy either of these conditions when callling checkout/manual: $this->user->isLogged() && $this->user->hasPermission('modify', 'sale/order')
I temporarily removed it by replace it with true so I can always manually add an order.
Using my input params, I do get this JSON:
"success":"Order totals has been successfully re-calculated!", however, checking the administrative orders list, it does not appear a new order gets added.
Update 3:
Despite the ability to create the order, I don't know how to submit the order.
First of all, it is dangerous to comment out the code $this->user->isLogged() && $this->user->hasPermission('modify', 'sale/order'). Instead add some kind of override to the parts that reference $this->request->post['customer_id'] so that you set the post data based on actual customer id. If not, it would be possible for regular customers to spoof log in and checkout data as another customer simply by sending whatever POST data they want.
In regards to the actual order creation, you'll note that checkout/manual returns a json with all necessary order data. All you need to do is add something like this after if (!isset($json['error'])) {
$this->load->model('checkout/order');
$json['order_id'] = $this->model_checkout_order->addOrder($json);
Then return the json to your mobile app and show a confirmation or do whatever you want with the order data. It might also be helpful to send a unique mobile app key along the validate whether or not the request is allowed and/or link to the appropriate customer account.
I downloaded the PHP quickstart from google (link) and put it online on a secure site.
When subscribing to timeline events, the file notify.php should be called. However, this never happens. For example when removing a timeline card I expect notify.php to be called, but it is not.
I really don't know how to dive deeper into this. Any idea someone?
-- edit --
Some more info on the issue (it was a long day yesterday..) ;)
The subscription is being set, when printing the subscription I see that the redirect url is correct:
$subscriptions = $mirror_service->subscriptions->listSubscriptions();
echo '<pre>';
print_r($subscriptions);
echo '</pre>';
results in:
Google_SubscriptionsListResponse Object
(
[__itemsType:protected] => Google_Subscription
[__itemsDataType:protected] => array
[items] => Array
(
[0] => Google_Subscription Object
(
[callbackUrl] => https://url/to/notify.php
[collection] => timeline
[id] => timeline
[kind] => mirror#subscription
[__notificationType:protected] => Google_Notification
[__notificationDataType:protected] =>
[notification] =>
[operation] =>
[updated] => 2014-03-21T09:34:45.391Z
[userToken] => 108736261363015154260
[verifyToken] =>
)
)
[kind] => mirror#subscriptionsList
)
In order to check if notify.php is called I'm creating a "log file" in a writable folder on the server:
<?php
// all the way on top of notify.php
$file = __DIR__ .'/db/log.txt';
function logfile($txt) {
global $file;
$str = is_file($file)? file_get_contents($file) : '';
file_put_contents($file, $str ."\n". $txt);
}
logfile('--- notify.php is being run ---');
//..
The logfile is written when I request https://url/to/notify.php, but the file is not written when I expect the subscription callback to fire.
Also the url https://url/to/notify.php has been added to the redirect URIs in the Google Developer Console, along with the oauth2callback.php
Ok I got it fixed.. Or actually, nothing was wrong..
I assumed that I would get notifications of newly created and deleted timeline items. Believe I read this somewhere.
However, today a collegue walked in who actually owns a glass device (the only one in the company). When I started playing with the menu items (you can't use them in the quickstart webapp) I could reply to a card and: notify.php was actually called!
Too bad this isn't well documented in the quickstart app itself.. But I am happy now :)
You should check to make sure that the subscription is actually created and contains the callback URL that you expect it to be.
Take a look at mirror-client.php:subscribe_to_notifications() and the "insertSubscriptions" case in index.php to verify the URL of the subscription.
You may also wish to add this function (from https://developers.google.com/glass/v1/reference/subscriptions/list) which will list your subscriptions. You can then use this to determine what URL is stored and verify that URL is a secure working one.
function printSubscriptions($service) {
try {
$subscriptions = $service->subscriptions->listSubscriptions();
foreach ($subscriptions->getItems() as $subscription) {
print 'Collection: ' . $subscription->getCollection();
print 'User token: ' . $subscription->getUserToken();
print 'Verify token: ' . $subscription->getVerifyToken();
print 'Callback URL: ' . $subscription->getCallbackUrl();
if ($subscription->getOperation()) {
print 'Operation:';
foreach ($subscription->getOperation() as $operation) {
print ' * ' . $operation;
}
print 'Operation: ALL';
}
}
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
}
}