Active Collab API: How to get projects - php

I'm trying out the ActiveCollab API for my first time. I had to use StackOveflow to figure out how to get the API token since the docs don't tell me this.
Below is my code:
/* GET INTENT */
$url = 'https://my.activecollab.com/api/v1/external/login';
$fields = array(
'email' => "email#email.com",
'password' => "****"
);
$intent = curl_post_connector($url, $fields);
$intent = $intent->user->intent;
/* GET TOKEN */
$url = 'https://app.activecollab.com/my_app_id/api/v1/issue-token-intent';
$fields = array(
'intent' => $intent,
'client_name' => 'My App Name',
'client_vendor' => 'My Company Name'
);
$token = curl_post_connector($url, $fields);
$token = $token->token;
Everything above works and get's the token properly. What I find really weird is that I have to use API v1 to get this, and the docs on ActiveCollab's site don't mention any URL for API v5. It seems like this is the approach everything is taking here on StackOverflow.
Now with the token, I try to get my list of projects:
/* GET PROJECT */
$url = 'https://app.activecollab.com/my_app_id/api/v1/users';
$headers = array (
"X-Angie-AuthApiToken" => $token
);
$projects = curl_get_connector($url, $headers);
var_dump($projects);
But this does not work. There is no error returned - it instead returns an array of languages for some reason! I don't want to paste the massive json object here, so instead I'll link you to a photo of it: https://www.screencast.com/t/7p5JuFB4Gu
UPDATE:
When attempting to use the SDK, it works up until I try getting the token (which is just as far as I got without the SDK). I'm getting Server Error 500, and when looking at the logs, it says:
/home/working/public_html/ac/index.php(21): ActiveCollab\SDK\Authenticator\Cloud->issueToken(123456789)
#1 {main}
thrown in /home/working/public_html/ac/SDK/Authenticator/Cloud.php on line 115
This is line 115 of Cloud.php:
throw new InvalidArgumentException("Account #{$account_id} not loaded");
I honestly don't think I did anything wrong... there must be something wrong with my account ID.
Just for kicks, I commented out that line, and the error disappears and the page loads fine - except now I have no token...

Related

Why WooCommerce REST API seems not working?

I'm currently working on my admin website using WooCommerce REST API, It works very well since last week but now it shows error like
Error: Sorry, you cannot list resources. [woocommerce_rest_cannot_view]
I don't change anything in my code, The authentication credentials are all fine. Thanks for any advice.
Edited:
protected $url = 'https://mywebsite.com';
protected const CONSUMER_KEY = 'ck_b7144d17091aa01a7a096154a445180c603d****';
protected const CONSUMER_SECRET = 'cs_cdb7705d4ad5bf29aa2b6366c55ac98397e4****';
function __construct(){
$this->woocommerce = new Woo(
$this->url,
self::CONSUMER_KEY,
self::CONSUMER_SECRET,
[
'wp_api' => true,
'version' => 'wc/v2',
]
);
}
This is often as a result of an setup issue, specifically with what values you've passed to verifySsl and queryStringAuth. You didn't post your code, so I can't tell you specifically, but these two resources might help:
https://github.com/woocommerce/wc-api-node/issues/43
https://robotninja.com/blog/fix-common-woocommerce-rest-api-issues/

WHMCS: How to get the current client in addon module clientarea page?

Given that I have a WHMCS addon that I call 'my_addon'. I created the main addon file 'my_addon.php' which does contain nothing than:
<?php
function my_addon_clientarea($vars) {
$client = null;
return array(
'pagetitle' => 'My Addon',
'breadcrumb' => array('index.php?m=my_addon'=>'My Addon'),
'templatefile' => 'views/myaddon_view',
'vars' => array(
'client' => $client
)
);
}
This does basically work. It does give me my template file, everything is passed through. My question is: How do I get the currently logged in client from within that function?
I didn't find any API method and I can't see any constant which does hold this information.
There must be a way to get the current client within the clientarea? Thanks for your help!
For those who do come after me and have the same problem: it's easy to solve. Turned out, that I just had to think it through... I found the client id to be available in the $_SESSION-variable.
So, if you are looking for the client's id:
<?php
function my_addon_clientarea($vars) {
$clientid = $_SESSION['uid'];
// And so on...
}
The official way to get current user information is:
$currentUser = new \WHMCS\Authentication\CurrentUser;
$user = $currentUser->user();
You can find more information here

Facebook graph PHP API batch request

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;

Get users details in mixpanel api

I'm trying to get user details via Mixpanel analytics but I am having difficulties to properly grasp how i should do this… data has been set using
mixpanel.people.identify()
Events and Segmentation requests seem to be ok; but I can't figure out how to query a request on the Engage endpoint.
as it turns out—there might be other ways to find this out but this one works for me:
you need to get engagement data this way
$data = $mp->request(array('engage'));
foreach($data->results as $user) {
$email = $user->{'$properties'}->{'$email'};
$last_seen_date = $user->{'$properties'}->{'$last_seen'};
$distinct_id = $user->{'$distinct_id'};
}
the distinct_id can then be used within the foreach() loop above to get events registered with this user:
$endpoint = array('stream', 'query');
$parameters = array(
'distinct_ids' => json_encode(array($distinct_id)),
'from_date' => '2014-02-10',
'to_date' => '2014-02-25',
);

twitter api (php) - statuses/destroy - returns nothing

I am using the tmOAuth library.
With the new 1.1 API, the following is returning an error code 400 - but authentication was done (same authentication for statuses works)! The library I am using works fine for all calls, except this one!
$tmhOAuth->request(
'POST', $tmhOAuth->url('https://api.twitter.com/1.1/statuses/destroy/MYIDHERE.json'),
array(
'id' => MYIDHERE
)
);
The twitter API documentation states that you don't have to send the id in post - but this doesn't make any difference.
I have tested this today with two different libraries, and neither work.
Any suggestions - does anyone know if there is an issue with it??
According to your comment, you have tested this in two libraries for the 1.1 API.
You haven't tested it in this one though. Instructions here, although you seem to already have your credentials in hand.
This basically proves that the library you are using has the issue, not the twitter API. So either submit a bug report on github (how else are they to know?), or use another library like the one above.
The exact code required using the above library (and it works, I just tested it):
// Require the library file
require_once('TwitterAPIExchange.php');
// Set up your credentials
$settings = array(
'oauth_access_token' => "YOUR_TOKEN",
'oauth_access_token_secret' => "YOUR_TOKEN_SECRET",
'consumer_key' => "YOUR_CONSUMER_KEY",
'consumer_secret' => "YOUR_CONSUMER_SECRET"
);
// Put the correct ID in the URL
$url = 'https://api.twitter.com/1.1/statuses/destroy/YOURIDHERE.json';
// Set the request type
$requestMethod = 'POST';
// Set the post fields
$postfields = array('id' => 'YOURIDHERE');
// Make the request
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
// Dump the response
$result = json_decode($json);
var_dump($result);
If you're using the twitteroauth php library from Abraham Williams and trying to delete old tweets/retweets you need to construct the post() query as such:
$response = $connection->post('statuses/destroy/'.$tweetID, array()); //Curl url output = statuses/destroy/$tweetID.json

Categories