FamilySearch / fs-php-lite

Lite PHP SDK for the FamilySearch API
Apache License 2.0
3 stars 4 forks source link

How to create Familysearch discussion and discussion comment on php lite #7

Closed deboyisgood closed 7 years ago

deboyisgood commented 8 years ago

Hello Sir, my app can now authenticate via php-lite api sample provide.

Now am having issues on how to create discussion and comment from the family search API for php. I couldnt find any sample code on that. here is the link to my sample testing. http://benjarsoft.com/root_meo1/examples/ can you please help me with php sample code on how to create disscussion and discussion comments. I have studied this link but does not know how to go about with it. Please sir this urgent as i have just few days left. below is the link of the family search data https://familysearch.org/developers/docs/api/discussions/Create_Discussion_usecase https://familysearch.org/developers/docs/api/discussions/Create_Comment_usecase

i need it eg. discussion.php and comment.php

my email is miracleyear2 at gmail[dot] com Thanks

justincy commented 8 years ago

Here's an outline:

// 1. Create a discussion
$response = $client.post('/platform/discussions/discussions', [
    'body' => [$discussionRequestBody] // the body would be the JSON from the usecases you linked to
]);
$discussionId = $response->headers['X-entitity-id'];

// 2. Attach the discussion to a person
$response = $client.post('/platform/tree/persons/12345', [
    'body' => [$discussionReferenceBody]
]);

// 3. Add a comment to the discussion
$response = $client.post("/platform/discussions/$discussionId/comments', [
    'body' => [$commentRequestBody]
]);
deboyisgood commented 8 years ago

Hi sir, I have included all the necessary files but still cannot get it to work. it says error " The page isn’t working

this is currently unable to handle this request. HTTP ERROR 500" It seems things are not properly formated

Am desperate as i need to round off my work. please assist me futher

below is what i have added from phplite api

<?php

include_once '_includes.php'; include_once '_header.php';

// 1. Create a discussion $discussionRequestBody= 'this is my mumys birtday discussion'; $response = $client.post('/platform/discussions/discussions', [ 'body' => [$discussionRequestBody] // the body would be the JSON from the usecases you linked to ]); $discussionId = $response->headers['X-entitity-id'];

// 2. Attach the discussion to a person $response = $client.post('/platform/tree/persons/12345', [ 'body' => [$discussionReferenceBody] ]);

$commentRequestBody='my mums first comment'; // 3. Add a comment to the discussion $response = $client.post("/platform/discussions/$discussionId/comments', [ 'body' => [$commentRequestBody] ]);

prettyPrint($response);

?>

include_once '_footer.php';

On Fri, Nov 25, 2016 at 7:44 AM, Justin notifications@github.com wrote:

Here's an outline:

// 1. Create a discussion$response = $client.post('/platform/discussions/discussions', [ 'body' => [$discussionRequestBody] // the body would be the JSON from the usecases you linked to]);$discussionId = $response->headers['X-entitity-id'];// 2. Attach the discussion to a person$response = $client.post('/platform/tree/persons/12345', [ 'body' => [$discussionReferenceBody]]);// 3. Add a comment to the discussion$response = $client.post("/platform/discussions/$discussionId/comments', [ 'body' => [$commentRequestBody]]);

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FamilySearch/fs-php-lite/issues/7#issuecomment-262982791, or mute the thread https://github.com/notifications/unsubscribe-auth/AT3I2_FygxzaqPavZLe3K7anJjiBQtNzks5rBwJ4gaJpZM4K8FSe .

deboyisgood commented 7 years ago

Hello Sir, any updates or solutions yets

justincy commented 7 years ago

$discussionRequestBody is not the right format. It needs to be formatted as shown in the Create Discussion usecase.

You could also check the error message in the response; it will contain clues.

deboyisgood commented 7 years ago

Hello Justin, this dicussion posting requires access_token. where can i get that. is this token my app key. Thanks

On Mon, Nov 28, 2016 at 6:35 AM, Justin notifications@github.com wrote:

$discussionRequestBody is not the right format. It needs to be formatted as shown in the Create Discussion usecase https://familysearch.org/developers/docs/api/discussions/Create_Discussion_usecase. You should also check the error message in the response; it will contain clues.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FamilySearch/fs-php-lite/issues/7#issuecomment-263286189, or mute the thread https://github.com/notifications/unsubscribe-auth/AT3I28mLcoEdUopiC-qJ6SEpbCXrAq8Mks5rCuamgaJpZM4K8FSe .

justincy commented 7 years ago

The SDK includes the access token automatically. You just need to provide the body.

{
  "discussions" : [ {
    "id" : "dis-MMMM-MMM",
    "title" : "1900 US Census, Ethel Hollivet",
    "details" : "Ethel Hollivet (line 75) with husband Albert Hollivet (line 74); also in the dwelling: step-father Joseph E Watkins (line 72), mother Lina Watkins (line 73), and grandmother -- Lina's mother -- Mary Sasnett (line 76).  ",
    "contributor" : {
      "resource" : "https://familysearch.org/platform/users/agents/JNYR-KJP",
      "resourceId" : "JNYR-KJP"
    },
    "numberOfComments" : 2
  } ]
}
deboyisgood commented 7 years ago

This is what i have tried and is returning a null value. it seems posting is not properly formatted or correctly done. posting discussion using curl after i have successfully login via familysearch API Call. I have include the php file _include.php on the phplite API. still am getting null displayed. please there is no time. can familysearch php developers help me fix this

Thanks

<?php

// 0 means unlimited timeout ini_set('max_execution_time', 0);

// Family Search API PHP FILES

include_once '_includes.php';

$url = "/platform/discussions/discussions";

$data = array( 'discussions' => array( 'id' => 'dis-MMMM-MMM', 'title' => '1900 US Census, Ethel Hollivet', 'details' => 'My mummy first first meet dady in 1940', ),

);

//echo $data;

$curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_HTTPHEADER, array(

'Content-Type: application/x-fs-v1+json', / 'Authorization: Bearer a02j000000KT0WhAAL',/

));

curl_setopt($curl, CURLOPT_POST, true); //curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

curl_close($curl);

$response1 = json_decode($json_response, true);

echo '

' . print_r($response1, true) . '

';

var_dump(json_decode($response1, true));

?>

On Wed, Nov 30, 2016 at 2:38 PM, Justin notifications@github.com wrote:

The SDK includes the access token automatically. You just need to provide the body.

{ "discussions" : [ { "id" : "dis-MMMM-MMM", "title" : "1900 US Census, Ethel Hollivet", "details" : "Ethel Hollivet (line 75) with husband Albert Hollivet (line 74); also in the dwelling: step-father Joseph E Watkins (line 72), mother Lina Watkins (line 73), and grandmother -- Lina's mother -- Mary Sasnett (line 76). ", "contributor" : { "resource" : "https://familysearch.org/platform/users/agents/JNYR-KJP", "resourceId" : "JNYR-KJP" }, "numberOfComments" : 2 } ] }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FamilySearch/fs-php-lite/issues/7#issuecomment-264019363, or mute the thread https://github.com/notifications/unsubscribe-auth/AT3I27auNN5iFkgpuzTqMlreYxra4zPUks5rDfr5gaJpZM4K8FSe .

justincy commented 7 years ago

There will be no response data if the request is a success. As you see in the usecase the server responds with an HTTP 201 Created and an empty body.