LinkedIn API v2 not returning data - php

I set up an app on linkedIn. Set up and tested code to return an access token. Which all worked fine. I tried to get basic profile data and it says I do not have proper access rights. I gave the app all basic permission other than write posts so I am at a loss for why nothing is being returned.
The error:{"serviceErrorCode":100,"message":"Not enough permissions to access: GET /me","status":403}
My code is below.THETOKENWOULDBEHERE in the live code is the token returned by the oauth process. If anyone has any insights it would be appreciated.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.linkedin.com/v2/me");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-RestLi-Protocol-Version:2.0.0','x-li-format: json','Authorization: Bearer *THETOKENWOULDBEHERE*'));
$response = curl_exec($ch);
curl_close($ch);
print_r($response);

If you are using V2 and you did not taken permission to use r_basicprofile
then either apply for permission to use r_basicprofile to linkedin
or use r_liteprofile + r_emailaddress
Check this : https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/migration-faq?context=linkedin/consumer/context

Related

POST works in facebook Graph Explorer but not from code

I have a php script that attempts to POST a post to a Facebook page via CURL, but fails with the error.
(#200) If posting to a group, requires app being installed in the group, and either publish_to_groups permission with user token, or both pages_read_engagement and pages_manage_posts permission with page token; If posting to a page, requires both pages_read_engagement and pages_manage_posts as an admin with sufficient administrative permission
The exact same POST works from Facebooks API Graph Explorer. The same page access token is used in both cases. I have checked the token in Facebook's token debugger and the permissions mentioned in the error are both present.
The code I'm using is:
$post_content = "message=".$message."&access_token=".$ae_page_access_token;
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v13.0/{page-ID}/feed');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Interestingly, I can post photos with captions to the page with the same access token from my php script without an error. The error only happens when using https://graph.facebook.com/v13.0/{page-ID}/feed -- the permissions just don't seem to work in this case. No idea why.
Can anyone suggest how to troubleshoot further or a possible cause? Any advice gratefully received
Well this is embarrassing. Misspelled parameter in a function call was the culprit. Works now.
Try this
$post_content = "message=".$message;
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v13.0/{page-ID}/feed?access_token=' . $ae_page_access_token);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
token place is in url like a get parameter https://developers.facebook.com/docs/facebook-login/guides/access-tokens#pagetokens

API I'm using can't be accessed unless Captcha is completed

I am trying to access API data from CraftingStore Public API.
When I am trying it on localhost, everything works like it should (1st pic, also printing results for to show).
However, when I am trying to view it on the actual website (2nd pic), it is not working but instead saying to enable cookies and to complete captcha.
When on localhost:
When on website:
Also code for accessing the API:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.craftingstore.net/v7/payments?page=1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'token:'.$cs_token
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
$dononame = $obj->data[0]->inGameName;
$donobuy = $obj->data[0]->packageName;
What can I do?
This is quite usual for API's with Cloudflare. You'll need to make a page rule for the API domain/URI to disable the Browser Integrity Check.
Source: https://support.cloudflare.com/hc/en-us/articles/200504045-Using-Cloudflare-with-your-API

Shopify REST API - how to connect?

Seems like a simple task but despite having read their docs I can't figure it out. I've gotten a Storefront Access Token, as per https://help.shopify.com/en/api/storefront-api/getting-started. Then I've used it in the CURL request below. However this just returns: {"errors":"[API] Invalid API key or access token (unrecognized login or wrong password)"}
I found their documentation a bit confusing as they have quite a few different APIs, and whilst it seems that this Storefront Access Token should work for this particular API, perhaps it doesn't?
$url = "https://mysite.myshopify.com/admin/api/2019-07/products/count.json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$headers = array(
'X-Shopify-Storefront-Access-Token: 2400d...........a999'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
print_r( $result);
curl_close($ch);
If you are using the Stronfront API your request should point to
https://mysite.myshopify.com/api/2019-07/products/count.json
and not to
https://mysite.myshopify.com/admin/api/2019-07/products/count.json
In addition Storefront Api request are different from the standard ones, have that in mind.

Unable to connect to Microsoft Dynamics CRM with PHP and Curl

I am trying to use PHP and CURL to connect to Microsoft Dynamics API so I can read client data from the CRM. The API guide can be found here:
https://msdn.microsoft.com/en-gb/library/mt593051.aspx
I've been into the Azure portal and set up a new application, and it gives me the credentials to use (client id, secret, etc.) and the url end points. Using these credentials I am able to successfully connect to the CRM and retrieve a bearer access token, but I am unable to get any further.
When I attempt to use the token to return data I receive the below error message:
HTTP Error 401 - Unauthorized: Access is denied
My assumption would be that I must be passing the token correctly?
My code is below.
<?php
// Step 1 - Use the credentials supplied by CRM to get an access token (this bit works okay)
$credentials = array(
'grant_type'=>'client_credentials',
'username'=>'xxxxxxxx',
'password'=>'xxxxxxxx',
'client_id'=>'xxxxxxxxxxxx',
'client_secret'=>'xxxxxxxxxx',
);
$urlSafeCredentials = http_build_query($credentials);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://login.microsoftonline.com/xxxxxxxxxxxxxx/oauth2/token');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlSafeCredentials);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
$response = curl_exec($ch);
$result = json_decode($response);
curl_close($ch);
// A BEARER access token is successfully returned
$token = $result->access_token;
// Step 2 - Use the access token to request data from the CRM (this bit fails with HTTP Error 401 - Unauthorized: Access is denied)
$ch = curl_init('https://clientspecificurl.crm4.dynamics.com/api/data/v8.1/accounts');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/x-www-form-urlencoded','Authorization: Bearer '.$token));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
print_r($response); // 401 Unauthorized ?!
?>
As far as I can tell there is nothing else to configure at the back end, any help would be much appreciated.
Based on the parameters to acquire the token, you were mixing the client credentials flow and resource owner password flow and lack of resource parameter.
The client credentials flow requires parameters grant_type,client_id,client_secret,resource and the value of grant_type is client_credentials.
The resource owner password credentials flow requires grant_type,client_id,client_secret,username,password,resource and the value of grant_type is password.
If you were using the client credentials flow, you can refer this blog for acquiring the token. And if you were using the resource owner password, you can refer this thread.
Details about difference of the flows in Oauth 2 please refer RFC 6749.
I wrote a lightweight PHP class for working with Dynamics 365 online Web API. You can find it here.
BTW in your code you should try "password" inside the grant_type instead of "client_credentials"

Review Board Authentication

I have a review board running on different server . I am using review board as a normal user of it and can comment on the reviews create it but i am not the admin f it. In order to view the review request or comment on it, i need to authenticate with it with my username and password. This is the access given to me. Review Board is an open source tool which is used by many organisations.
Here are the WEB API of it:- (authenticating link) http://www.reviewboard.org/docs/manual/1.5/webapi/2.0/authenticating/#logging-in
Now i am using wamp as server on my local system . I am using php as server side language. I want to use the Review Board API for fetching the data with my credientals. I am using php curl and written this code for authenticating:-
<?php
$ch = curl_init('http://SERVERIP');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Basic realm="Web API"'));
$output = curl_exec($ch);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Basic md5encryptedusernamepassword'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
var_dump($info);
curl_close($ch);
var_dump($output);
?>
This code is not authenticating. Please have a look. Any kind of guideline will be helpful. I have spent much time understanding it. Please help.
You should set headers with key:"Authorization",value:" Basic #{Base64.encode64("username:password")}"。
Then you can access the api which is need authentication.

Categories