I have a store in Dutchie.com. I want to access it's products using API key.
This has to do via Dutchie API using GraphQL integrated with PHP.
This is the Sample API Key:
public-eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJBUEktQ0xJRU5UIiwiZXhwIjozMzE4NjM5Mjc0NSwiaWF0IjoxNjI5NDgzOTQ1LCJpc3MiOiJodHRwczovL2R1dGNoY29tIiwianRpIjoiNGMtOTMyOC00MjhkLWEyYTMtOWQzMTc2ZTUwODY0IiwiZW50ZXJwcmlzZV9pZChLWExYTctNDM3OC05NWY4LTNlYzVzBiNSIsInV1aWQiOiI0M2ZlMjdkNy1iZWU2LTQxOTgtYWNhMi03N2Y5Y2I3MjI5MGIifQ.hCQWpcQ5uhKnZOSVQDA5SCMkx5kopC7H3upeU-1jMpg
This is the GraphQL Ping mutation.
mutation Ping {
ping {
id,
time
}
}
Dutchie End Point: https://plus.dutchie.com/plus/2021-07/graphql
http header parameter
{
"Authorization":"Bearer API KEY HERE"
}
Ping output
Basically I want to run GraphQL query in my PHP page. I'll add into my WordPress page later.
I have tried php-graphql-client php library.
Can someone help me to do this using above library or another one really appreciate. I wasted too much time for this as I have only few knowledge of GraphQL.
This is the code what I have tried.
$client = new Client(
'https://plus.dutchie.com/plus/2021-07/graphql',
['Authorization => Bearer API Key here']
);
// Create the GraphQL mutation
$gql = (new Mutation('Ping'))
->setSelectionSet(
[
'id',
'time',
]
);
// Run query to get results
try {
$results = $client->runQuery($gql);
}
catch (QueryError $exception) {
// Catch query error and desplay error details
print_r($exception->getErrorDetails());
exit;
}
// Display original response from endpoint
var_dump($results->getResponseObject());
// Display part of the returned results of the object
var_dump($results->getData()->pokemon);
// Reformat the results to an array and get the results of part of the array
$results->reformatResults(true);
print_r($results->getData()['data']);
Error what I got.
https://github.com/guzzle/psr7/blob/master/src/MessageTrait.php
Instead of:
$client = new Client(
'https://plus.dutchie.com/plus/2021-07/graphql',
['Authorization => Bearer API Key here']
);
Try
$client = new Client(
'https://plus.dutchie.com/plus/2021-07/graphql',
['Authorization' => 'Bearer API Key here']
);
Related
I am using the Facebook marketing api to create a campaign, adset, creative and ads and I am using the PHP sdk 3.0 to manage them in Facebook.
I can create them successfully. Here is code to create a campaign:
$fields = array();
$params = array(
'name' => 'API Test - vish',
'objective' => 'CONVERSIONS',
'status' => 'PAUSED',
);
try{
$campaign = $this->ad_account->createCampaign($fields,$params);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
echo $campaign->id;
I want to update details of a campaign.
I did some research and found this link, which states, that it is possible to update campaign details, but it does not provide a correct way to do it.
Anybody please let me know how I can update Facebook campaign details using its api.
I know it is old question but I had the same issue and I've solved it this way:
$campaign = new Campaign($campaignId);
$campaign->updateSelf($fields, $params); // in $params are updated properties
Maybe it will help someone.
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...
I have a return object coming from instagram.
I am trying to skate the entire build DB table structure process, I understand Mongo is the ideal DB to use for this task.
I am using the regular instagram libraries https://github.com/cosenary/Instagram-PHP-API
and my test code runs without error.
I don have the PhP PECL mongo libraries installed, I should be good to go.
session_start();
require 'vendor/autoload.php';
use MetzWeb\Instagram\Instagram;
$instagram = new Instagram(array(
'apiKey' => 'xxx',
'apiSecret' => 'xxx',
'apiCallback' => 'http://103.238.173.97/success.php'
));
$accessToken = $instagram->getAccessToken();
$_SESSION['InstagramAccessToken'] = $accessToken;
$instagram->setAccessToken($_SESSION['InstagramAccessToken']);
$popular = $instagram->getPopularMedia();
// After getting the response, let's iterate the payload
var_dump($popular);
added just now:
$conn = new MongoClient('mongodb://localhost/?w=1');
$db = $conn->instagram;
// access collection
$collection = $db->instagram1;
$collection->insert($popular);
How would I construct a PDO query to 'autobuild' the table structure just like the JSON object at reply from my request?
instagram JSON object
Repaste of object. Most got cut off due to size
Update:
I tried to insert straight into a collection, I get no error but the DB is still the same size
show dbs
Data 0.078GB
admin (empty)
instagram 0.078GB
local 0.078GB
test 0.078GB
week1 (empty)
while running this code with the app instalation,i am getting the Unprocessable Entity status code 422 error.
Here is the code
$sc = new ShopifyClient($_SESSION['shop'], $_SESSION['token'], $api_key, $secret);
$charge = array
(
"webhooks"=> array
(
"topic"=>"orders/create",
"address"=>"http://www.abc123no.com/nomi/s.php?key=123456789",
"format"=>"json"
)
);
try
{
$webhooks = $sc->call('POST','/admin/webhooks.json',$charge);
}
catch (ShopifyApiException $e)
{
var_dump($e->getResponseHeaders());
}
Error code 422 is for validation errors. The body of the response will describe the error to help you debug your application.
e.g. The response might be: {"errors":{"address":["for this topic has already been taken"]}}
Your error appears to be from using the wrong format for the request. The create endpoint doesn't take an array of webhooks, and you should use the singular "webhook" for the top-level key.
The Webhook API documentation has the correct format for the request body.
Change webhooks to webhook , it might create bad request error
"**webhooks**"=> array
(
"topic"=>"orders/create",
"address"=>"http://www.abc123no.com/nomi/s.php?key=123456789",
"format"=>"json"
)
I'm trying to post a check-in in user's feed, using offline access. But I keep getting various errors, but if i try to post message/video/picture everything works great.
So here is my code:
public function postCheckIn()
{
$post=array(
'access_token'=> $this->token,
'message'=>'Test check-in!',
'place'=>'172822562765332',
'coordinates' => json_encode(array(
'latitude' => '55.772855818478',
'longitude' => '37.687225341797'
))
);
try
{
$res=$this->fb->api('/'.$this->uid.'/checkins', 'POST', $post);
}
catch(FacebookApiException $e)
{
$res=$e->getMessage();
}
return $res;
}
When I'm running this code, I get an exception:
Requires a valid Place Page ID
I check this place using https://developers.facebook.com/tools/explorer/, and it returns some valid info.
BTW, I have publish_checkins permission.
Do I always have to provide placeId, and coordinates? Can I provide one of this parameters?
And how to get it to work?
Thank you.
https://graph.facebook.com/172822562765332 doesn't have latitude longitude data
i suppose that's why
this is a snippet that work... your params looks correct to me
formPost->addField("message",message );
formPost->addField("place",place);
formPost->addField("coordinates",coordinates);
formPost->addField("tags",tags );
formPost->addField("application","{\"id\": \"204264309603362\",\"name\": \"mobile borg\"}");
qDebug()<<"FacebookGraph::post"<
QString feed=url+"me/checkins";
You can always use the publish_stream as this will get around any issues you are having with offline publishing.
http://developers.facebook.com/docs/reference/rest/stream.publish/