Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. function httpPost($url, $data)
  6.  
  7. {
  8.  
  9.     $curl = curl_init($url);
  10.  
  11.     curl_setopt($curl, CURLOPT_POST, true);
  12.  
  13.     curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  14.  
  15.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  16.  
  17.     $response = curl_exec($curl);
  18.  
  19.     curl_close($curl);
  20.  
  21.     return $response;
  22.  
  23. }
  24.  
  25.  
  26.  
  27. $BUSINESS_MANAGER_ID = "";
  28.  
  29. $ACCESS_TOKEN = "";
  30.  
  31. $CREATE_OFFLINE_SET_URL = "https://graph.facebook.com/v5.0/$BUSINESS_MANAGER_ID/offline_conversion_data_sets";
  32.  
  33.  
  34.  
  35. $data = array(
  36.  
  37.   'name' => 'TEST OFFLINE EVENT SET API',
  38.  
  39.   'access_token' => $ACCESS_TOKEN
  40.  
  41. );
  42.  
  43.  
  44.  
  45. $results = httpPost($CREATE_OFFLINE_SET_URL, $data);
  46.  
  47. echo $results;
  48.  
  49. $created = json_decode($results);
  50.  
  51.  
  52.  
  53. $offline_id = $created->id;
  54.  
  55. $offline_upload_url = "https://graph.facebook.com/v5.0/$offline_id/events";
  56.  
  57.  
  58.  
  59. $sample_data = array(
  60.  
  61.   'upload_tag' => 'sales_data',
  62.  
  63.   'access_token' => $ACCESS_TOKEN,
  64.  
  65.   'data' => array(
  66.  
  67.     array(
  68.  
  69.       'match_keys' => array(
  70.  
  71.             'phone' => array(hash('sha256', '6505555555'), hash('sha256', '6505555555')),
  72.  
  73.             'email' => array(hash('sha256', 'email@test.com'), hash('sha256', 'email@test.com'))
  74.  
  75.       ),
  76.  
  77.       'currency' => 'USD',
  78.  
  79.       'value' => 16,
  80.  
  81.       'event_name' => 'Purchase',
  82.  
  83.       'event_time' => 1456870902
  84.  
  85.     ),
  86.  
  87.     array(
  88.  
  89.       'match_keys' => array(
  90.  
  91.             'phone' => array(hash('sha256', '6505555555'), hash('sha256', '6505555555')),
  92.  
  93.             'email' => array(hash('sha256', 'email@test.com'), hash('sha256', 'email@test.com'))
  94.  
  95.       ),
  96.  
  97.       'currency' => 'USD',
  98.  
  99.       'value' => 16,
  100.  
  101.       'event_name' => 'Purchase',
  102.  
  103.       'event_time' => 1456870902
  104.  
  105.     )
  106.  
  107.   )
  108.  
  109. );
  110.  
  111.  
  112.  
  113. var_dump(httpPost($offline_upload_url, $sample_data));
  114.  
  115.  
  116.  
  117. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement