I am currently attempting to query the user information for any given discord account. Its pretty simple, I give the website a Discord User ID and it outputs that specific users account information.
I believe my issue is related directly to how discord authorizes their bots and after about an hour of google searching I figured it would be better to ask here.
Any help much appreciated!
Current Code:
$IDURL = "https://discord.com/api/v8/users/" . $UserID;
$CurlInitID = curl_init();
curl_setopt_array( $CurlInitID, [
CURLOPT_URL => $IDURL,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bot *private key removed*"
]
]);
$Return = curl_exec($CurlInitID);
curl_close($CurlInitID);
die($Return);
Return From Website:
{"message": "405: Method Not Allowed", "code": 0}
What is the most effective way of programmatically filling out an HTML form on a website, using data from a dataset (either CSV, JSON, or similar..) and then retrieving the results of that submitted form into another dataset? I would like to be able to do this multiple times, populating the form with different parameters each time, always retrieving those parameters from my input dataset.
I was reading about Selenium and HTMLUnit, which seem to do similar things. But they require installing dependencies and learning how to use them. Would it be overkill? Is there an easier way to do this by maybe writing my own script?
I tried writing a php curl script, but this one doesn't generate the headers or cookies that the request requires, so I'm not able to retrieve anything.
<?php
/**
* Send a POST requst using cURL
* #param string $url to request
* #param array $post values to send
* #param array $options for cURL
* #return string
*/
function curl_post($url, array $post = NULL, array $options = array())
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
?>
I'm not sure if that's the right approach.
Any tips/resources would be appreciated.
You can write this script in Selenium - it's just a browser driver, it will fill the form from the client side. If the page isn't very complicated, you can use library requests in Python and directly send POST data to the final page. Requests is a faster lib, and to write a script sending POST data you will need 5 mins of learning.
I have a list of our Eventbrite events inside our PHP CodeIgniter web app.
Here's the code fo my events list:
<?php
$token = "our_token";
$organizer_id = "our_organizer_id";
$request_url = "https://www.eventbriteapi.com/v3/events/search/?sort_by=date&organizer.id=".$organizer_id."&token=".$token;
$params = array('sort_by' => 'date', 'organizer.id' => $organizer_id, 'token' => $token);
$context = stream_context_create(
array(
'http' => array(
'method' => 'GET',
'header' => "Content-type: application/x-www-form-urlencoded\r\n"
)
)
);
$json_data = file_get_contents( $request_url, false, $context );
$response = json_decode($json_data, true);
?>
I used $response inside a loop so I could display them. Here's what it looks like.
Now, I want the users to be able to RSVP inside the system and not by redirecting through Eventbrite. Here's a sample event from the list.
I know it's possible but how can I make it work?
This is my first time to work on Eventbrite and their official documentation is in Python. I already emailed their support if they could provide me a good documentation in PHP but I haven't heard from them.
Although there's an SDK and some libraries available, I don't how how to use them and some of them with examples are deprecated.
Your help is highly appreciated.
This is not possible via Eventbrite's API endpoints. However, you can use Eventbrite's embedded checkout widget to accomplish this.
Here are the Eventbrite Articles on Embedded Checkout:
https://www.eventbrite.com/support/articles/en_US/Multi_Group_How_To/how-to-sell-eventbrite-tickets-on-your-website-through-an-embedded-checkout?lg=en_US
https://www.eventbrite.com/support/articles/en_US/How_To/how-to-add-eventbrite-s-embedded-checkout-to-your-wordpress-org-site?lg=en_US
I hope this helps you!
I am trying to get to get clicks and spend data for ad campaigns.
I am currently getting all ad campaign ID's with a curl request which returns about 260 ID's.
I want to make a batch request and get the clicks, spend, start and end dates for each ID.
I have found the PHP SDK FacebookRequest() function very confusing so have been trying to make cURL requests.
Would really appreciate some help because I am just stumped at the moment. Is it best to use to FacebookRequest() function or can I continue using the cURL requests?
Not sure if I am on the right track but essentially what I have at the moment is all the campaign ID's which I group with a method, relative_url and body and then pass to a requestHandler function. The code is as follows:
$ad_account_ids = <ad_account_id>;
$ad_campaign_ids = FbAdCampaign::all()->lists('ad_campaign_id')->toArray();
foreach ($ad_campaign_ids as $key => $value) {
$ad_campaign_ids[$key] = array(
"method" => "GET",
"relative_url" => "v2.4/act_".$ad_account_ids."/adgroups",
"body" => "campaign_id=".$value."&redownload=1&bid_type=CPC&bid_info={\"clicks\":150}&creative={\"creative_id\":\"{result=create_creative:$.id}\"}&targeting={\"countries\":[\"US\"]}&name=test1"
);
$fields[] = array(
'access_token' => $access_token,
'batch' => $ad_campaign_ids[$key]
);
// $url = 'https://graph.facebook.com/v2.4/act_'.$ad_campaign_ids.'/adcampaign_groups?access_token='.$access_token;
$url = 'https://graph.facebook.com/';
$data = RequestHandler::curlRequest($url);
Ok got it.
Had to prepend the /GET data to the end of the URL to pass to the request handler.
as follows:
$url = 'https://graph.facebook.com/v2.3/act_'.$ad_account_ids.'/adcampaign_groups?access_token='.$access_token;
Google Analytics, by just placing its sourcecode on my website, automatically tracks everything I used to need (pageviews, unique visitors).
But now, I need to track events, and the only way to do this is to do it server-side. Each time any users does an specific action i need to track, the server posts data to google to track the information, as explained here:
https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event
And it does works amazingly perfect, but, since I realiced, I am now receiving a LOT of visits from Spain, doubling the visits from USA. And before I implemented the event tracking, Spain wasn't even part of the top 10 countries.
Today I have realiced that my servers are in Spain, and that may be causing the issue.
How can I track the event, without making it count as a pageview?
$url = 'http://www.google-analytics.com/collect';
$data = array('v' => '1', 'tid' => 'UA-HIDDEN-1', 'cid' => $_SERVER["REMOTE_ADDR"], 'ni' => '1', 't' => 'event', 'ec' => '', 'ea' => 'JUMP', 'el' => '');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
Thank you very much!!
You are sending the IP adress as a client id, which is wrong. For one, the client id is supposed to be an UUID. Secondly, Analytics won't recognize that these events belong to an existing user.
You'd need to grab the existing client id for an existing user on the web page:
ga(function(tracker) {
var clientId = tracker.get('clientId');
});
and then send it back to the server and use it in your request (1). At the moment GA cannot assign correct geo information since the events do not belong to the session of the user who initiates the event (this quite possibly affects some other metrics, too).
(1) You might as well read the GA cookie in PHP, but Google recommends against it since the cookie format might change without notice. The script above will always return a correct client id even if the cookie format changes.
Updated: I have read a bit more documentation and while my answer seems still somewhat relevant it's probably wrong for the actual use case - Geo is determined by IP and the serverside script will still send the servers IP. So quite possibly (haven't done the science yet) this would look like one visitor with two devices instead of a single visitor.
Update 2: Apparently it is now possible to include the users IP adress as parameter, so this answer is possibly no longer relevant.
Here is a techopad presentation about mixing UA client- and serverside, maybe that helps.
An event in and of itself is not a pageview. See: Event Tracking
Is there a specific reason why you need to track events server side and pageviews from the normal ga.js client-side code?
You can easily track events from the client side, if you were unaware of that:
Click Link to Track Event
Assuming that you needed to keep events AND pageviews on the server side:
<?php
//Put SERVER_ADDR into a var
$request_ip = $_SERVER['REMOTE_ADDR'];
// Put any server IPs you need to filter out below in an array
$localhosts = array('127.0.0.1','192.168.15.1','10.1.10.1');
// Use this later
$url = 'http://www.google-analytics.com/collect';
Now, Figure out what to do with the REMOTE_ADDR check if its in our list above. then build an array of type to send GA (events, pageviews)
$actions = array();
// Note that the values are arbitrary and will let you do what you need.
if(in_array($request_ip)){
//Only track event, or track pageview differently, or track two events.
$handle_myServer = true;
$actions = ('event');
} else {
// Track everyone else
$handle_myServer = false;
$actions = ('event','pageview','mySpecialPageview','mySpecialEvent');
}
Finally We have built a list of events we can use in flow control with existing code for pageviews, user timing, events, etc. Be creative!
foreach($actions as $action){
$data = null; $options=null;
if($handle_myServer){
$someFlagForGA = 'RequestFromSpainServer';
}
if($action == 'event'){
$data = array('v' => '1'
, 'tid' => 'UA-HIDDEN-1',
,'cid' => $request_ip
,'ni' => '1'
, 't' => 'event'
, 'ec' => $someFlagForGA,
,'ea' => 'JUMP', 'el' => ''
);
} elseif($action == 'pageview'){
$data = array('v' => '1', 'tid' => 'UA-HIDDEN-1'
, 't' => 'pageview'
, 'dh'=> 'yourGAenabledDomainHere.com'
, 'dp'=> 'ViewedPage.html'
, 'dt'=> 'homepage'.' SERVER VISITED '.$someFlagForGA
);
} else {
// Do whatever else
}
// Would be better to do below with a single function
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
) ,$data);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context) or die('Error!!');
}
?>