I am trying to create an Issue in my own repo using Github API, but for some reason it keeps throwing me an error
Route::post('/issue/create/{repo}',function ($_repo){
$client = new Client([
// Base URI is used with relative requests
'base_uri' => 'https://api.github.com',
// You can set any number of default request options.
// 'timeout' => 2.0,
]);
$url = '/repos/rehan-dckap/'.$_repo.'/issues';
// Set various headers on a request
$response = $client->request('POST', $url, [
'query' => [
'title' => 'IssueCreation',
'body' => 'ThPI',
'assignee' => '',
'milestone' => 1,
'labels' => [],
'assignees' => []
],
'headers' => [
'Authorization' => 'Bearer TOKENTOKENTOKENTOKEN'
]
]);
return response($response->getBody());
});
ERROR
Client error: POST https://api.github.com/repos/rehan-dckap/qatouch-api-docs/issues?title=IssueCreation&body=ThPI&assignee=&milestone=1 resulted in a 422 Unprocessable Entity response: { "message": "Invalid request.\n\nFor 'links/0/schema', nil is not an object.", "documentation_url": "https://develo (truncated...)
Can someone guide me?
I've taken quite a bit of time to try and understand what the problem is here, but without running the code itself it will be a bit tricky. Can you provide an online sandbox with that code so I can play with it? I'm happy to provide the token myself. There's two main things here.
First the 422 generally means that there was an error parsing the payload. Looking at your payload, and the error message I would try to start by removing all non-mandatory fields starting by the arrays. If we look at the error message it's saying Nil is a not an object. My best guesses would be problems with the arrays or the assignee string.
Overall my tip in these cases is to reduce the API call to the bare functional. minimum and try to isolate the problem. I would go as far as using the GitHub Example they've posted on the API page and even remove the assignee since it's been deprecated:
{
"title": "Found a bug",
"body": "I'm having a problem with this.",
"milestone": 1,
"labels": [
"bug"
]
}
Hope this helps.
here you can check the error code: https://developer.github.com/v3/
Sending invalid fields will result in a 422 Unprocessable Entity response.
HTTP/1.1 422 Unprocessable Entity
Content-Length: 149
{
"message": "Validation Failed",
"errors": [
{
"resource": "Issue",
"field": "title",
"code": "missing_field"
}
]
}
Related
When PATCHing to a record using the Crud plugin and Crud.Api listener, a successful PATCH returns a 200 OK with an empty data array in the response.
{
"success": true,
"data": []
}
When validation fails after a PATCH, a 422 Unprocessable Entity with the following response is returned:
{
"message": "A validation error occurred",
"url": "\/admin\/users\/edit\/4.json",
"code": 422,
"file": "\/app\/vendor\/friendsofcake\/crud\/src\/Listener\/ApiListener.php",
"line": 189
}
but I expected something like:
{
"success": false,
"data": [
"errors": [...]
]
}
https://crud.readthedocs.io/en/latest/listeners/api.html#http-put-edit
If success is false a HTTP response code of 422 will be returned,
along with a list of validation errors from the model in the data
property of the response body.
Does the plugin need to be configured to return the errors?
I'm not overly familiar with the Crud plugin, but that response looks like the default CakePHP exception renderer response, so I'd guess that you probably haven't configured your app to use the Crud exception renderer:
config/app.php
'Error' => [
'exceptionRenderer' => \Crud\Error\ExceptionRenderer::class,
// ...
],
Quote from the docs:
Note: However if you are using CakePHP 3.3+’s PSR7 middleware feature the exceptionRenderer config won’t be used and instead you will have to set the Error.exceptionRenderer config in config/app.php to 'Crud\Error\ExceptionRenderer' as following
See Crud Docs > Listeners > API > Exception handler
I'm using Loopback and
I'm trying to user auth for graph api without javascript sdk or passport
I got the code successfully however I can't exchange it with access token
I followed this guide https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/#confirm
my get request is https://graph.facebook.com/v2.7/dialog/oauth?code={xxxx}&client_secret={xxxx}&client_id={xxx}&redirect_uri={myURL}
myURL is the one used to get the code but not be used again if I understand
If I understand correctly I should it the access_token in the body of the response instead I get this error
{
"error": {
"message": "Unknown path components: /oauth",
"type": "OAuthException",
"code": 2500,
"fbtrace_id": "HXe+214tGpW"
}
}
It looks like a bug in the docs. The first call is to www.facebook.com in a browser.
See here for an example client https://github.com/yschimke/oksocial/blob/master/src/main/java/com/baulsupp/oksocial/services/facebook/FacebookAuthFlow.java
The second should be to something like https://graph.facebook.com/v2.7/oauth/access_token
$response = $fb->sendRequest(
'GET',
'/oauth/access_token',
[
'client_id' => $config['client_id'],
'client_secret' => $config['client_secret'],
'grant_type' => 'fb_exchange_token',
'fb_exchange_token' => $short_token
],
$short_token,
null,
'v2.7');
The API I'm accessing requires a custom authorization header that is a combination of the publicKey that is passed in when the client is instantiated and the complete URI of the API endpoint. I want to pull the baseUrl and operation uri out of the service description and use them to create the authorization header, but I can't figure out how to do this when calling the instantiated client.
This is the service description:
{
"name": "FranchiseSystem",
"apiVersion": "1",
"baseUrl": "https://apidev.example.com",
"description": "REST API client",
"operations": {
"GetFranchiseList": {
"httpMethod": "GET",
"uri": "v1/franchise",
"summary": "Returns an array of franchises."
},
"GetReviews": {
"httpMethod": "GET",
"uri": "v1/review",
"summary": "Returns an array of reviews."
}
}
}
This is the client setup:
$testClient = new JunknetClient([
'publicKey' => '1234567890',
]);
This is the call to the instantiated client with the name of the operation:
$result = $testClient->GetFranchiseList();
or:
$result = $testClient->GetReviews();
When testClient->GetFranchiseList is called, I need to create the authorization header using the publicKey and the values of baseUrl and uri for GetFranchiseList.
When testClient->GetReviews is called, I need to create the authorization header using the publicKey and the values of baseUrl and uri for GetReviews.
You might want to have a look at the following links from the Guzzle docs.
Request Options - Headers
Authentication Parameters
I was able to solve my problem by using and event emitter and subscriber. It's a bit messy, but it get's the job done.
private function handleCredentialsOptions(Collection $config) {
//Build authorization header from $config values
$this->getHttpClient()->getEmitter()->on('before',
function (BeforeEvent $e) use(&$config) {
$this->getHttpClient()->setDefaultOption('headers', [
'Authentication' => '',
]);
$path = $e->getRequest()->getUrl();
$authValue = $config['publicKey'].';;';
$authValue .= time().';';
$authValue .= strtoupper(md5($config['privateKey'] . $path));
$this->getHttpClient()->setDefaultOption('headers', [
'Authentication' => $authValue,
]);
});
}
My app was doing well yesterday and posting custom stories with mention tagging but from today its not working and telling me : -
Received Facebook error response of type OAuthException: Unknown path components: /mynamespace:customaction
Error code : 2500
{
"error": {
"message": "Unknown path components: /namespace:customaction",
"type": "OAuthException",
"code": 2500
}
}
$response = $facebook->api(
'me/mynamespace:customaction',
'POST',
array(
'treat' => "http://www.mywebsite.com/12321425125"
)
);
I have not changed any configurations or anything and it has stopped working all of a sudden. Please help me identify the issue - maybe there is an issue at Facebook end.
Im working on fb app using PHP client and FQL.Looks like that fb api doesnt support this. You can get max random 500 members with FQL. But when group has more than 500 members there is no way how to get total count of members.
I need only number dont care about member details.
Anyone can help me please?
I have actually found that you cannot, it is by design apparently. I wanted to know this myself about a month ago, and found that no matter what parameters you pass in to the graph api, you can not get past the 500th member. Even if you tell it to start at number 450 and give you 200, it will give you only 450-500.
Here's me asking, and the unfortunate answer:
http://forum.developers.facebook.net/viewtopic.php?id=82134
you can use graph api 2.0 and sdk 4.0
you can use below code
$url1= "https://graph.facebook.com/".$gid."/members?limit=10000&access_token=".$_SESSION['fb_token'];
if(!extension_loaded('curl') && !#dl('curl_php5.so'))
{
return "";
}
$parsedUrl = parse_url($url1);
$ch = curl_init();
$options = array(
CURLOPT_URL => $url1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => array("Host: " . $parsedUrl['host']),
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => false
);
curl_setopt_array($ch, $options);
$response_count = #curl_exec($ch);
$json_count = json_decode($response_count);
foreach ($json_count as $item_count)
{
$cnt=count($item_count);
break;
}
You can use the summary parameter which will return a total_count value.
/v2.11/{GROUP_ID}?fields=members.limit(0).summary(true)
It also works when searching for groups:
/v2.11/search?q=stackoverflow&type=group&fields=id,name,members.limit(0).summary(true)
{
"data": [
{
"id": "667082816766625",
"name": "Web Development Insiders",
"members": {
"data": [
],
"summary": {
"total_count": 2087
}
}
},
{
"id": "319262381492750",
"name": "WEB Developers India",
"members": {
"data": [
],
"summary": {
"total_count": 10240
}
}
}...
]
}
Make a query to:
https://graph.facebook.com/v2.11/{group-id}/members?limit=1500&access_token={token}
(replace {group-id} by the numeric group identification and {token} by your access token).
You will get a response like this:
{
"data": [
{
"name": "Foo bar",
"id": "123456",
"administrator": false
},
...
],
"paging": {
"cursors": {
"before": "QVFIUkwzT3FKY0JSS2hENU1NUlZAocm9GelJMcUE3S1cxWWZAPYWx1cUQxcXFHQUNGLUJnWnZAHa0tIdmpMT0U5ZAjRBLUY5Q2ZAGbmwwVTNoSHhLc1BCc2dvVTF3",
"after": "QVFIUkFoU3lYR2tXc09adkg5OGhlbHRWRk1GYkZAzQU1DalRSY05zOVl5aE1tcjRMS3lXLURaVWNMOGZArWTVxS2hPQUVGVWxhbXZAyZA0p3azVKM2hBSEp3YlpR"
}
},
"next": "https://graph.facebook.com/v2.11/123928391023981/members?access_token=EAACEdEose0cBALBDrdgLyVOjzW4mz6G3d3Yj1fTGYqygVgYq0JCDZAi0zYsY90pSSQ9hQZCn3TdwfXIAiyoXH5oUYcA4hOcCI9jztkkUhbBv9tEQ3ZBEEuHpmkm3kmgvk1HNq5mo6BM0hz8XkOLVh3twIdz83KhB9SkqxuxHeFD9GWsQqjys6XTuL2315QZD&pretty=0&limit= 1500&after=QVFIUkFoU3lYR2tXc08adkg5OGhlbHRWYk1GYkZAzQU1DalRSY05zOVl5aQ1tcjRMS3lXLURaVWNMOGZArWTVxS2hPQUVGVWxhbXZAyZA0p3azVKM1hBSEp3YlpR"
}
Then follow this algorithm:
Make a count variable with a 0 value.
Count the objects in the data array of the latest response and add the count to the count variable.
If the latest response has the next property, make a request to the URL which is the next property value and return to the step 2. Otherwise you have finished, the count of members is the count variable value.
This way is not very good because the more members there are in the group the more queries are required. I would be better to parse the number of members from the group page HTML but I can't find reliable way to do it.
Update 2017.10.19: If the Facebook API response size is more then about 345KB, Facebook returns an error: Please reduce the amount of data you're asking for, then retry your request. It is about 1997 members. So you need to set the limit request parameter to 1500 not to face the error.
Update 2018.01.26: There is a way to get a count of members using a single request: https://stackoverflow.com/a/47783306/1118709
Update 2018.01.31: After 90 days from releasing Graph API v2.12 the request will require an access token of an admin of the group. Source: Graph API docs / v2.12 changelog / 90-day breaking changes
You should do it with an FQL query on the group_member table like:
SELECT uid FROM group_member WHERE gid = <group_id> limit 500 offset 500
Example here: Is it possible / how to get number of a particular Facebook Group members (even if number of them is 500+)?