Discord API - UserID Request in PHP - php

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}

Related

Eventbrite PHP RSVP

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!

How to get Google Adwords ad cost over time with PHP?

So I have successfully established an ouath connection with Google Adwords, but I fail to realize how a request should look like in order to get the ad cost over time. What parameters should I use?
I was hoping to find a more simple solution, like the api calls made to Google Analytics:
public function getAudienceMetricsAll($google_analytics_account_id)
{
$curl = new Curl("https://www.googleapis.com/analytics/v3/data/ga");
$curl->setParams([
"ids" => "ga:" . $google_analytics_account_id,
"dimensions" => "ga:date",
"metrics" => "ga:users,ga:newUsers,ga:percentNewSessions,ga:sessions,ga:bounces,ga:bounceRate,ga:avgSessionDuration,ga:goalStartsAll,ga:pageviews,ga:pageViewsPerSession",
"start-date" => "730daysAgo",
"end-date" => "today",
"max-results" => 10000
]);
$curl->setHeaders([
"Authorization" => "Bearer " . #$this->aim_account->settings["credentials"]["access_token"]
]);
$data = $curl->sendRequest("json");
return $data;
}
I mean, just the url and params I need to send in the body of the request. But I don't seem to be able to find such information.
Thank you for your time! Any help is welcomed!

NETELLER TransferIn: Authentication credentials are invalid

I'm having a problem in integrating the Neteller API to transfer money from a user account to our merchant account. I've succcessfully received the accessToken (using auth_code grant type), however when I try using transferIn I am getting the error Authentication credentials are invalid.
Here is my code:
//getting the accessToken from NETELLER's response
$accessToken = $_POST['accessToken'];
$service_url = "https://test.api.neteller.com/v1/transferIn";
$curl = curl_init($service_url);
$curl_post_data = array(
"paymentMethod" => array(
"type" => "neteller",
"value" => "netellertest_USD#neteller.com"
),
"transaction" => array(
"merchantRefId" => (string)date('YmdHis'),
"amount" => 25,
"currency" => "USD"
),
"verificationCode" => "234124"
);
$jsonDataEncoded = json_encode($curl_post_data);
curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonDataEncoded);
$headers = array(
"Content-type: application/json",
"Authorization: Bearer " . $accessToken
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
$curl_response = curl_exec($curl);
curl_close($curl);
However, I am getting this error:
{ "error":{ "code": "5279", "message": "Authentication credentials are invalid" } }
Am I missing anything in the transferIn curl postfields?
Thanks!
You shouldn't be using the auth_code grant type, the correct one is client_credentials. This is explained in detail on page 41 of the latest REST API guide, which you can download from your merchant account >> "Developer" tab >> "Documentation" page.
Just to clarify - the auth_code flow obtains authorization from the user (for ex. for subscription payments, additional account profile information, etc). Although it will work for payments too, it will add 2 more steps to the flow and can be a conversion killer.
Additionally, I found some issues in your code, which you should also address:
The amount you are trying to deposit is too small -- you need to convert the transaction amount to the smallest currency unit before sending it to the API. For example - you want to request a deposit for $5, the smallest currency unit for USD is cents, which is 1/100 of a dollar, so you need to send $5 * 100 = 500 to the API. Important to note here is that the HUF, KRW and JPY currencies do not have subunits, so the amount needs to be sent to the API as is (no conversion needed).
The verificationCode for the USD test account is 270955. This information is available on page 153 of the REST API guide.
Please try to implement the client_credentials grant type flow and post here if you encounter any issues, I will try to assist you. Alternatively, you can add me on Skype (it is in my profile information).

Forward data from php script to calendar

I have a project where I need to do the following: retrieve some data from a form, fill the database, create a response for the user and post the data to a third party. To give an example, it's like booking a ticket to a concert.The ajax call: You buy the ticket, you receive a response (whether the purchase was successful), a php script sends data to the database, and someone may be announced that a new ticket was bought. Now, I need to pass data to that "someone". Which is what I don't know how to do.
Or, like when someone posts a comment to my question on stackoverflow, I get a notification.
In my particular case, the user creates an event, receives a response and I will need to have certain parameters posted by the user on a calendar. It is important that I could hardly integrate the calendar with the script retrieving the data. I would rather need to "forward" the data to the calendar- quite like pushing notifications.
Can anyone please give me a clue what should I use, or what should I need in order to do the above?
The process will go like this:
AJAX
user----> php script->database
|_ calendar
So if i get you right, you could post your data to the calendar via curl:
$url = "http://www.your-url-to-the-calendar.com";
$postData = array(
"prop1" => "value1",
"prop2" => "value2",
"prop3" => "value3"
);
//urlify the data for the post
$data_string = "";
foreach ($postData as $key => $value)
$data_string .= urlencode($key) . '=' . urlencode($value) . '&';
$data_string = rtrim($data_string, '&');
//will output --> prop1=value1&prop2=value2=prop3=value3
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_POST => count($postData),
CURLOPT_POSTFIELDS => $data_string
));
$result = curl_exec($ch);
If your third party calendar does not require authentication than this would be the best way to post it, if you can not write to the database yourself.
When it requires authentication you would have to first login via curl (send credentials via curl-post, receive cookies, send cookies with your data)
Hope this helps.

Dynamic W3C Validation

I have a small element on my website that displays the validity of the current page's markup. At the moment, it is statically set as "HTML5 Valid", as I constantly check whether it is, in fact, HTML5 valid. If it's not then I fix any issues so it stays HTML5-valid.
I would like this element to be dynamic, though. So, is there any way to ping the W3C Validation Service with the current URL, receive the result and then plug the result into a PHP or JavaScript function? Does the W3C offer an API for this or do you have to manually code this?
Maintainer of the W3C HTML Checker (aka validator) here. In fact the checker does expose an API that lets you do, for example:
https://validator.w3.org/nu/?doc=https%3A%2F%2Fgoogle.com%2F&out=json
…which gives you the results back as JSON. There’s also a POST interface.
You can find more details here:
https://github.com/validator/validator/wiki/Service-»-HTTP-interface
https://github.com/validator/validator/wiki/Service-»-Input-»-POST-body
https://github.com/validator/validator/wiki/Service-»-Input-»-GET
https://github.com/validator/validator/wiki/Output-»-JSON
They do not have an API that I am aware of.
As such, my suggestion would be:
Send a request (GET) to the result page (http://validator.w3.org/check?uri=) with your page's URL (using file_get_contents() or curl). Parse the response for the valid message (DOMDocument or simple string search).
Note: This is a brittle solution. Subject to break if anything changes on W3C's side. However, it will work and this tool has been available for several years.
Also, if you truly want this on your live site I'd strongly recommend some kind of caching. Doing this on every page request is expensive. Honestly, this should be a development tool. Something that is run and reports the errors to you. Keep the badge static.
Here is an example how to implement W3C API to validate HTML in PHP:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://validator.w3.org/nu/?out=json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '<... your html text to validate ...>',
CURLOPT_HTTPHEADER => array(
"User-Agent: Any User Agent",
"Cache-Control: no-cache",
"Content-type: text/html",
"charset: utf-8"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
//handle error here
die('sorry etc...');
}
$resJson = json_decode($response, true);
$resJson will look like this:
{
"messages": [
{
"type": "error",
"lastLine": 13,
"lastColumn": 110,
"firstColumn": 5,
"message": "Attribute “el” not allowed on element “link” at this point.",
"extract": "css\">\n <link el=\"stylesheet\" href=\"../css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.min.css\">\n <",
"hiliteStart": 10,
"hiliteLength": 106
},
{
"type": "info",
"lastLine": 294,
"lastColumn": 30,
"firstColumn": 9,
"subType": "warning",
"message": "Empty heading.",
"extract": ">\n <h1 id=\"promo_codigo\">\n ",
"hiliteStart": 10,
"hiliteLength": 22
},....
Check https://github.com/validator/validator/wiki/Service-»-Input-»-POST-body for more details.

Categories