I need to figure out how to iterate through a Facebook group feed that's returned as an object from the Facebook graph. Everything is working fine until I try to go through the object and get all the data so that I can format and print it.
This is my request...
$request = new FacebookRequest( $session, 'GET', '/group_id/feed' );
$response = $request->execute();
$object = $response->getGraphObject()->asArray();
It returns the feed of my group in an object, for example...
Array
(
[data] => Array
(
[0] => stdClass Object
(
[id] => POST ID
[from] => stdClass Object
(
[id] => MEMBER ID
[name] => MEMBER NAME
)
[to] => stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[name] => Film Club
[id] => GROUP ID
)
)
)
[message] => MESSAGE
[picture] => PICTURE URL
[link] => LINK URL
[icon] => https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif
[actions] => Array
(
[0] => stdClass Object
(
[name] => Comment
[link] => LINK
)
[1] => stdClass Object
(
[name] => Like
[link] => LINK
)
)
[privacy] => stdClass Object
(
[value] =>
)
[type] => photo
[object_id] => OBJECT ID
[application] => stdClass Object
(
[name] => Facebook for iPhone
[namespace] => fbiphone
[id] => ID
)
[created_time] => 2014-10-02T00:39:00+0000
[updated_time] => 2014-10-02T00:51:53+0000
[likes] => stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[id] => ID
[name] => NAME
)
[1] => stdClass Object
(
[id] => ID
[name] => NAME
)
)
[paging] => stdClass Object
(
[cursors] => stdClass Object
(
[after] => ODI5MTk3ODI3MTEzOTk1
[before] => MTU1NjEwNzcxMTI3MjIyNQ==
)
)
)
[comments] => stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[id] => COMMENT ID
[from] => stdClass Object
(
[id] => MEMBER ID
[name] => NAME
)
[message] => COMMENT
[can_remove] => 1
[created_time] => 2014-10-02T00:45:23+0000
[like_count] => 1
[user_likes] =>
)
)
[paging] => stdClass Object
(
[cursors] => stdClass Object
(
[after] => WTI5dGJXVnVkRjlqZFhKemIzSTZNamczT0RreU9EQXhOREF4TlRnd09qRTBNVEl5TVRFeE1UTTZMVEU9
[before] => WTI5dGJXVnVkRjlqZFhKemIzSTZNamczT0RreE5EazBOek0xTURRME9qRTBNVEl5TVRBM01qTTZMVEU9
)
)
)
)
)
)
And to loop through all this I've tried a number of different things, stuff I've found here and everywhere else on the internet. I haven't been able to find any way to output more than just the POST ID. It's been a while since I've programmed anything, but this shouldn't be this hard. Can anyone help me figure this out?
Related
Code:
$response = $s3->copyObject(array(
'Bucket' => $bucket,
'Key' => $key,
));
Response:
Aws\Result Object
(
[data:Aws\Result:private] => Array
(
[CopyObjectResult] => Array
(
[ETag] => "s906113sa3401932f56f79ec75a1c877"
[LastModified] => Aws\Api\DateTimeResult Object
(
[date] => 2021-05-31 04:51:54.000000
[timezone_type] => 2
[timezone] => Z
)
)
[Expiration] =>
[CopySourceVersionId] =>
[VersionId] =>
[ServerSideEncryption] =>
[SSECustomerAlgorithm] =>
[SSECustomerKeyMD5] =>
[SSEKMSKeyId] =>
[SSEKMSEncryptionContext] =>
[BucketKeyEnabled] =>
[RequestCharged] =>
[#metadata] => Array
(
[statusCode] => 200
[effectiveUri] => https://bucket-dev.s3.amazonaws.com/store111/RawVideo/videogallery/file_example_MP4_480_1_5MG_1622436712.mp4
[headers] => Array
(
[x-amz-id-2] => DFzipf5adLLXV1435xCQO5d+R0LgDDl74o143UicbYF5biXv78G/j4HEDhoS8FsBY9C8HC+mOw8=
[x-amz-request-id] => 4SVDA143BSDZ49A6QJK
[date] => Mon, 31 May 2021 04:51:54 GMT
[content-type] => application/xml
[content-length] => 234
[server] => AmazonS3
)
[transferStats] => Array
(
[http] => Array
(
[0] => Array
(
)
)
)
)
[ObjectURL] => https://bucket-dev.s3.amazonaws.com/store111/RawVideo/videogallery/file_example_MP4_480_1_5MG_1622436712.mp4
)
[monitoringEvents:Aws\Result:private] => Array
(
)
)
The above out I want to get the ETag value in the below code
$etag = $response->get('ETag');
I am getting the $etag value as empty. Please help and let me know how I will get it?
Note: It was working fine for aws v2 when we migrate it from aws v2 to v3 we are getting different types of responses.
After checking finally I just call the below:
$etag = $response['CopyObjectResult']['ETag'];
It's working fine as expected.
I want to get index items by range according to the docs: https://docs.aws.amazon.com/clouddirectory/latest/developerguide/directory_objects_range_filters.html
Here is my request:
array (
'ConsistencyLevel' => 'EVENTUAL',
'DirectoryArn' => 'myARN',
'IndexReference' =>
array (
'Selector' => '/Global/fieldIndex',
),
'RangesOnIndexedValues' =>
array (
0 =>
array (
'AttributeKey' =>
array (
'FacetName' => 'Field',
'Name' => 'fieldPath',
'SchemaArn' => 'myARNSCHEMA',
),
'Range' =>
array (
'EndMode' => 'LAST',
'StartMode' => 'INCLUSIVE',
'StartValue' =>
array (
'StringValue' => 'deal.applications.applicants',
),
),
),
),
)
And I have the error response:
Limited range must be the first range after prefixes
'[range[<FIRST>, <LAST>], range[precedes{6465616c2e6170706c69636174696f6e732e6170706c6963616e7473}, <LAST>]]' -
{"Message":"Limited range must be the first range after prefixes '[range[<FIRST>, <LAST>], range[precedes{6465616c2e6170706c69636174696f6e732e6170706c6963616e7473}, <LAST>]]'"}
Does anybody know what am I doing wrong?
Thanks.
Sorted this in another way changing the request:
array (
'ConsistencyLevel' => 'EVENTUAL',
'DirectoryArn' => 'arn',
'IndexReference' =>
array (
'Selector' => '/Global/fieldIndex',
),
'RangesOnIndexedValues' =>
array (
0 =>
array (
'AttributeKey' =>
array (
'FacetName' => 'Field',
'Name' => 'fieldPath',
'SchemaArn' => 'schmaarn',
),
'Range' =>
array (
'EndMode' => 'EXCLUSIVE',
'StartMode' => 'INCLUSIVE',
'StartValue' =>
array (
'StringValue' => 'Global.deal.applications.applicants.',
),
'EndValue' =>
array (
'StringValue' => 'Global.deal.applications.applicants/',
),
),
),
),
)
I have a custom post_type 'publications' and it has a Repeater field 'linked_author' with a sub-field 'paper_linked_author' - a post object.
Here is the code to get all of the publications post and run a loop to get all authors linked to each post.
$args = array(
'posts_per_page' => '-1',
'post_type' => 'publications'
);
$the_query = new WP_Query( $args );
$post_ids = wp_list_pluck( $the_query->posts, 'ID' );
echo "<pre>";
print_r($post_ids);
echo "</pre>";
$artist_list = array();
foreach($post_ids as $post_id){
$artist_repeater = get_field('linked_author', $post_id);
echo "<pre>";
print_r($artist_repeater);
echo "</pre>";
if ($artist_repeater) {
$speakers = get_sub_field('paper_linked_author');
if ($speakers && count($speakers)>0)
{
foreach ($speakers as $speaker)
{
echo $speaker->ID; //$speaker is a post object//
}
}
}
}
I have been able to get all the sub-field values of each publication post however I'm not able to echo details of each linked author - the sub-field values. A print_r($artist_repeater) shows below details for one of the posts.
So, my question is how to list all unique authors from below print_r() array? Also, I need to link each author name such that clicking will bring list of all publications post he/she is linked to? Please help!
Array
(
[0] => Array
(
[paper_linked_author] => WP_Post Object
(
[ID] => 4885
[post_author] => 1
[post_date] => 2018-06-26 04:56:29
[post_date_gmt] => 2018-06-26 04:56:29
[post_content] =>
[post_title] => Q1-Test
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => q1-test
[to_ping] =>
[pinged] =>
[post_modified] => 2018-06-26 05:14:13
[post_modified_gmt] => 2018-06-26 05:14:13
[post_content_filtered] =>
[post_parent] => 0
[menu_order] => 0
[post_type] => people
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
[1] => Array
(
[paper_linked_author] => WP_Post Object
(
[ID] => 2115
[post_author] => 1
[post_date] => 2017-03-28 05:47:01
[post_date_gmt] => 2017-03-28 05:47:01
[post_content] =>
[post_title] => Julius Ceaser
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => julius-ceaser
[to_ping] =>
[pinged] =>
[post_modified] => 2018-06-25 11:02:55
[post_modified_gmt] => 2018-06-25 11:02:55
[post_content_filtered] =>
[post_parent] => 0
[menu_order] => 0
[post_type] => people
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
)
Just so it helps others, I solved the above problem with below code.
Basically, I was looking to list all authors who have written at least one Publication. So, earlier I was querying publications custom post_type and then looping each publication to list linked authors and that is where the above print_r() dump can be seen.
So, instead I queries all authors (a custom post_type) and then queries publications to match the key "linked_author_$_paper_linked_author" with the ID of the author post. It worked.
<?php
add_filter( 'posts_orderby' , 'posts_orderby_lastname' );
$args = array(
'post_type' => 'people',
'posts_per_page' => -1, // Unlimited posts
'post_status' => 'publish'
// Order alphabetically by name
);
$loops = new WP_Query( $args );
while ($loops -> have_posts()) : $loops -> the_post();
$args = array(
'numberposts' => -1,
'post_type' => 'publications',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'linked_author_$_paper_linked_author',
'compare' => '=',
'value' => get_the_ID()
)
)
);
// query
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ):
?>
<ul>
<li><?php echo the_title(); ?></li>
</ul>
<?php
endif;
endwhile;
?>
Does anyone know what this error means? I've read that it could be PHP version issue. Could it also be due to permissions? Or say.. like a firewall?
SoapFault Object ( [message:protected] => SOAP-ERROR: Parsing Schema: can't import schema from
'http://www.w3.org/2005/05/xmlmime' [string:Exception:private] => [code:protected] => 0 [file:
protected] => /person/ok/my_library/Zend/Soap/aplace.php [line:protected] => 51 [trace
:Exception:private] => Array ( [0] => Array ( [file] => /person/ok/my_library/Zend/Soap/Client
/aplace.php [line] => 51 [function] => SoapClient [class] => SoapClient [type] => -> [args] =>
Array ( [0] => http://myWSDL:7001/web/10/Intw?WSDL [1] => Array ( [encoding]
=> UTF-8 [soap_version] => 2 [trace] => 1 ) ) ) [1] => Array ( [file] => /person/ok/my_library/
Zend/Soap/Client.php [line] => 1024 [function] => __construct [class] => Zend_Soap_Client_aplace
[type] => -> [args] => Array ( [0] => Array ( [0] => Zend_Soap_Client Object ( [_encoding:protected]
=> UTF-8 [_classmap:protected] => [_faultExceptions:protected] => Array ( ) [_soapVersion:protected]
=> 2 [_uri:protected] => [_location:protected] => [_style:protected] => [_use:protected] =>
[_login:protected] => [_password:protected] => [_proxy_host:protected] => [_proxy_port:protected]
=> [_proxy_login:protected] => [_proxy_password:protected] => [_local_cert:protected] =>
[_passphrase:protected] => [_compression:protected] => [_connection_timeout:protected] =>
[_stream_context:protected] => [_features:protected] => [_cache_wsdl:protected] =>
[_user_agent:protected] => [_wsdl:protected] => http://myWSDL:7001/web/101/Intw?WSDL
[_soapClient:protected] => [_lastMethod:protected] => [_soapInputHeaders:protected] => Array ( )
[_permanentSoapInputHeaders:protected] => Array ( ) [_soapOutputHeaders:protected] => Array ( ) )
[1] => _doRequest ) [1] => http://myWSDL:7001/web/101/Intw?WSDL [2] =>
Array ( [encoding] => UTF-8 [soap_version] => 2 [trace] => 1 ) ) ) [2] =>
Array ( [file] => /my_library/place.php [line] =>
1180 [function] => _initSoapClientObject [class] => Zend_Soap_Client
[type] => -> [args] => Array ( ) ) [3] => Array ( [file] => /my_library/place.php
[line] => 1104 [function] => getSoapClient [class] => Zend_Soap_Client [type] => -> [args] => Array ( ) ) [4] =>
Array ( [file] => /some/path/to/my/file.php [line] =>
149 [function] => __call [class] => Zend_Soap_Client [type] => -> [args] => Array ( [0] => command [1] =>
Array ( [0] => Array ( [arg0] => Array ( [Username] => myUsername:) [Password] =>
myPassword:) [InputField] => Summary [ItemId] => 9999999 ) ) ) ) ) [5] =>
Array ( [file] => /some/path/to/my/file.php
[line] => 149 [function] => command [class] => Zend_Soap_Client [type] => -> [args] =>
Array ( [0] => Array ( [arg0] => Array ( [Username] => myUsername:) [Password] => myPassword:) [InputField] =>
Summary [ItemId] => 9999999 ) ) ) ) [6] => Array ( [file] => /some/path/to/my/file.php
[line] => 256 [function] => getPickFieldValue [class] => Code_Tracker_PriNvcProcessController [type] => -> [args] =>
Array ( [0] => Dev Task Component ) ) [7] => Array ( [file] => /person/ok/my_library/Zend/Controller/Action.php [line] => 513 [function] =>
mksFormAction [class] => Code_Tracker_PriNvcProcessController [type] => -> [args] => Array ( ) ) [8] =>
Array ( [file] => /some/other/path/to/another/file.php [line] => 289 [function] =>
dispatch [class] => Zend_Controller_Action [type] => -> [args] => Array ( [0] => mksFormAction ) ) [9] =>
Array ( [file] => /person/ok/my_library/Zend/Controller/Front.php [line] => 954 [function] => dispatch [class] =>
Zend_Controller_Dispatcher_Standard [type] => -> [args] => Array ( [0] => Zend_Controller_Request_Http Object ( [_paramSources:protected] =>
Array ( [0] => _GET [1] => _POST ) [_requestUri:protected] => /yet/another/path/to/a/js/form?code_id=706 [_baseUrl:protected] =>
[_basePath:protected] => [_pathInfo:protected] => /yet/another/path/to/a/js/form [_params:protected] => Array ( [module] =>
code_tracker [controller] => pri-nvc-process [action] => mks-form ) [_rawBody:protected] => [_aliases:protected] => Array ( )
[_dispatched:protected] => 1 [_module:protected] => code_tracker [_moduleKey:protected] => module [_controller:protected] =>
pri-nvc-process [_controllerKey:protected] => controller [_action:protected] => mks-form [_actionKey:protected] => action ) [1] =>
Zend_Controller_Response_Http Object ( [_body:protected] => Array ( ) [_exceptions:protected] => Array ( ) [_headers:protected] => Array ( )
[_headersRaw:protected] => Array ( ) [_httpResponseCode:protected] => 200 [_isRedirect:protected] => [_renderExceptions:protected] =>
[headersSentThrowsException] => 1 ) ) ) [10] => Array ( [file] => /again/another/path/to/initialize.php [line] => 67 [function] =>
dispatch [class] => Zend_Controller_Front [type] => -> [args] => Array ( ) ) [11] => Array ( [file] => /again/another/path/to/initialize.php
[line] => 43 [function] => dispatch [class] => application_Init [type] => :: [args] => Array ( ) ) [12] => Array ( [file] =>
/again/another/path/to/initialize.php [line] => 55 [function] => init [class] => application_Init [type] => :: [args] =>
Array ( ) ) [13] => Array ( [file] => /another/path/but/to/html/index.php [line] => 20 [function] => start [class] =>
application_Init [type] => :: [args] => Array ( ) ) ) [previous:Exception:private] => [faultstring] => SOAP-ERROR:
Parsing Schema: can't import schema from 'http://www.w3.org/2005/05/xmlmime' [faultcode] => WSDL )
There could still be proxy (preventing access to schema from your application) but your browser might already be preconfigured for it.
Within your php application, can print log output for the HTTP code returned for that schema location? Haven't use PHP before but perhaps using HttpClient - something like this: http://scripts.incutio.com/httpclient/examples.php
Here is my code:
$session = $facebook->getSession();
var_dump($session);/*it says session is perfectly established*/
try {
$uid = $facebook->getUser();
echo '<br>';
var_dump($uid);/*User id is found*/
$fb_user = $me = $facebook->api('/me');/*PHP execution doesn't go forward, here it breaks*/
echo '<br>';
var_dump($fb_user);/*PHP execution doesn't come up to here*/
EDITED:
I have print_r the $exception in the catch section and got the following long message:
FacebookApiException Object
(
[result:protected] => Array
(
[error_code] => 6
[error] => Array
(
[message] => name lookup timed out
[type] => CurlException
)
)
[message:protected] => name lookup timed out
[string:private] =>
[code:protected] => 6
[file:protected] => /home/abusadat/public_html/.../facebook.php
[line:protected] => 614
[trace:private] => Array
(
[0] => Array
(
[file] => /home/abusadat/public_html/.../facebook.php
[line] => 575
[function] => makeRequest
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => https://graph.facebook.com/me
[1] => Array
(
[method] => GET
[access_token] => ******...******
)
)
)
[1] => Array
(
[file] => /home/abusadat/public_html/.../facebook.php
[line] => 539
[function] => _oauthRequest
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => https://graph.facebook.com/me
[1] => Array
(
[method] => GET
)
)
)
[2] => Array
(
[file] => /home/abusadat/public_html/.../facebook.php
[line] => 492
[function] => _graph
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => /me
)
)
[3] => Array
(
[file] => /home/abusadat/public_html/.../fb-connect.php
[line] => 31
[function] => api
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => Array
(
[0] => Facebook Object
(
[appId:protected] => ******...******
[session:protected] => Array
(
[access_token] => ******...******
[base_domain] => abusadat.com
[expires] => 1312567200
[secret] => ******...******
[session_key] => ******...******
[sig] => ******...******
[uid] => ******...******
)
[signedRequest:protected] =>
[sessionLoaded:protected] => 1
[cookieSupport:protected] => 1
[baseDomain:protected] =>
[fileUploadSupport:protected] =>
)
[1] => _graph
)
[1] => Array
(
[0] => /me
)
)
)
[4] => Array
(
[file] => /home/abusadat/public_html/.../index.php
[line] => 29
[args] => Array
(
[0] => /home/abusadat/public_html/.../fb-connect.php
)
[function] => include_once
)
)
)
I am using SDK version 2.1.2. I have some restriction to use SDK 3 or greater.
My guess is that an exception is being thrown and that you don't see it because your PHP error reporting settings are not tuned properly.
Add this to the top of your PHP file:
ini_set('display_errors', 1);
error_reporting(E_ALL);
You should then see a PHP error when visiting the page.