Help with tweet media entities - php

I just came across Tweet Entities and I want to add it to my tweets! I have read over and over in the API, but I still can't get it to work. This is what I have:
$entities = array(
"media_url" => $picture_url,
"url" => $short_url,
"type" => "photo"
);
$status = $connection->post('statuses/update', array('status' => $twitterStatus, 'include_entities' => 1, 'entities' => $entities));
Part of print_r($status) includes:
[entities] => stdClass Object (
[user_mentions] => Array ( )
[hashtags] => Array ( )
[urls] => Array (
[0] => stdClass Object (
[url] => http://myf.la/sh/9nlex
[indices] => Array (
[0] => 6
[1] => 28
)
[expanded_url] =>
)
)
)
[retweet_count] => 0
[place] =>
[in_reply_to_user_id] =>
[in_reply_to_status_id] =>
What else do I have to add in my entities array? You can't add everything the docs asks you too.
I think it's a known issue since it's a new API. Read here.

No, you don't need to specify your media (entities) manually - twitter will extract it automatically.
http://api.twitter.com/1/statuses/show/82425283357052929.xml?include_entities=1 --- here is my recent tweet, with entities.

Using OAuth method you can do the POST statusesupdate_with_media..
Just download this example and check
I posted about this last week.. check this and download sample code
Change the config.php key from your Twiiter App
<?php
define('API_KEY', '');/*Your Consumer key*/
define('API_SEC','');/*Your Consumer secret*/
?>
Run index.html file you can see the form to POST the twitter update...

Related

How to Filter course object fields from Google Classroom courses list using PHP

I want to filter course object fields from the Google Classroom courses list. When I call API for the course list It responds to all objects. But I want specific course object names, sections from the course list.
$optParams = array(
'pageSize' => 100,
'courses' => 'name','section',
'fields' => 'courses(id)'
);
$results = $service->courses->listCourses($optParams);
How I get specific course object names, sections from the course list using PHP.
The below problem shows if the code test
Fatal error: Uncaught Google\Exception: (list) unknown parameter: 'courses' in C:\xampp\htdocs\classroom\vendor\google\apiclient\src\Service\Resource.php:153 Stack trace: #0 C:\xampp\htdocs\classroom\vendor\google\apiclient-services\src\Classroom\Resource\Courses.php(122): Google\Service\Resource->call('list', Array, 'Google\\Service\\...') #1 C:\xampp\htdocs\classroom\quickstart1.php(70): Google\Service\Classroom\Resource\Courses->listCourses(Array) #2 C:\xampp\htdocs\classroom\quickstart1.php(132): test('406487331584') #3 {main} thrown in C:\xampp\htdocs\classroom\vendor\google\apiclient\src\Service\Resource.php on line 153
If the code part will as below then the response has all objects names without value and shows fields object name,section and value which I want.
$optParams = array(
'pageSize' => 100,
'fields' => 'courses(name,section)'
);
$results = $service->courses->listCourses($optParams);
List Courses Response Object:
[courses] => Array
(
[0] => Google\Service\Classroom\Course Object
(
[collection_key:protected] => courseMaterialSets
[alternateLink] =>
[calendarId] =>
[courseGroupEmail] =>
[courseMaterialSetsType:protected] => Google\Service\Classroom\CourseMaterialSet
[courseMaterialSetsDataType:protected] => array
[courseState] =>
[creationTime] =>
[description] =>
[descriptionHeading] =>
[enrollmentCode] =>
[guardiansEnabled] =>
[id] =>
[name] => Android
[ownerId] =>
[room] =>
[section] => PC-D
[teacherFolderType:protected] => Google\Service\Classroom\DriveFolder
[teacherFolderDataType:protected] =>
[teacherGroupEmail] =>
[updateTime] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
[1] => Google\Service\Classroom\Course Object
(
[collection_key:protected] => courseMaterialSets
[alternateLink] =>
[calendarId] =>
[courseGroupEmail] =>
[courseMaterialSetsType:protected] => Google\Service\Classroom\CourseMaterialSet
[courseMaterialSetsDataType:protected] => array
[courseState] =>
[creationTime] =>
[description] =>
[descriptionHeading] =>
[enrollmentCode] =>
[guardiansEnabled] =>
[id] =>
[name] => CSS
[ownerId] =>
[room] =>
[section] => PC-D
[teacherFolderType:protected] => Google\Service\Classroom\DriveFolder
[teacherFolderDataType:protected] =>
[teacherGroupEmail] =>
[updateTime] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
But I need to Look like as below:
[courses] => Array
(
[0] => Google\Service\Classroom\Course Object
(
[name] => Android
[section] => PC-D
)
)
What you are looking for is something called partial response. All of the google apis support it as far as I know.
The way it works is you request the properties you want to see. It can be a bit tricky to get to work I recommend using the try me on the documentation page to test it out before you add it to your code.
Lets look at how it works though.
This is the response object for your method. It returns a list of courses. So the first thing you will probably want is courses.
{
"courses": [
{
object (Course)
}
],
"nextPageToken": string
}
Then you may want to limit the object within courses. Which is a course object A course object has an id. So what if you just wanted all the ids for all the course.
The code should look something like this.
$optParams = array(
'pageSize' => 100,
'courses' => 'name','section',
'fields' => 'courses(id)'
);
$results = $service->courses->listCourses($optParams);
Note i dont have access to this api so i cant test it let me know if you have any issues.
update from updated question and comment
What fields does is it ensures that the fields you ask for are only retured. So by the looks of it the changes i sugested are working
However you state you want to see something like this
[courses] => Array
(
[0] => Google\Service\Classroom\Course Object
(
[name] => Android
[section] => PC-D
)
)
That is not possible. The API will just return nulls in the fields that you request partial response is just intended to make the request faster. Your code should just ignore the null fields.

json decode transforms Facebook payload

Facebook POST request from lead ads test tool is getting transformed on my end:
Facebook lead ad testing tool:
https://developers.facebook.com/tools/lead-ads-testing
Code to accept payload:
$input = json_decode(file_get_contents('php://input'), true);
Framework: CakePHP 2.0
Debug:
2017-07-07 12:12:27 Debug: Array
(
[entry] => Array
(
[0] => Array
(
[changes] => Array
(
[0] => Array
(
[field] => leadgen
[value] => Array
(
[ad_id] => 0
[form_id] => 7.2426956441826E+14
[leadgen_id] => 7.9242177426971E+14
[created_time] => 1499447542
[page_id] => 4.8242822517084E+14
[adgroup_id] => 0
)
)
)
[id] => 482428225170841
[time] => 1499447543
)
)
[object] => page
)
PHP versions: 5.5.9
The problem:
[form_id] => 7.2426956441826E+14
[leadgen_id] => 7.9242177426971E+14
When it should be:
[form_id] => 724269564418262
[leadgen_id] => 792421774269707
So it seems to be converting those numbers for some reason.
I have a clone of this app on an older version of PHP ( 5.4 ) and dont seems to be having this issue there.
I suspect you may need to set the 'options' of json_decode to use JSON_BIGINT_AS_STRING.
Check out http://php.net/manual/en/function.json-decode.php
And this post led me to the possible solution PHP JSON large integers

Problems with Reddit SDK (API)

I'm trying to get the last posts of a subreddit - I'm using the jcleblanc reddit sdk (https://github.com/jcleblanc/reddit-php-sdk) and I don't know why It's not working - I receive the following message ewhen I try to acess my website
403 Forbidden
Request forbidden by administrative rules.
The https://ssl.reddit.com/prefs/apps is configured okay - I just don't know why It's not working. I'm using the following function:
<?php
$reddit = new reddit();
$response = $reddit->getListing("calculus", 5);
print $response
?>
It'd be nice to have some help - I'm not any expert developer, just trying to make something.
Thanks :-)
Hey guys - I managed to get it working using an old version of that don't uses OAuth.
$reddit = new reddit($USER, $PASS);
print_r($reddit);
print_r($reddit->getListing("calculus", 1));
It's working! but, on the page I receive all the information, for example:
reddit Object ( [kind] => Listing [data] => stdClass Object ( [modhash] => jvfddbr7sg6a1787beebf94c0a61cc4c2be6e5fb2106da9f4b [children] => Array ( [0] => stdClass Object ( [kind] => t3 [data] => stdClass Object ( [domain] => self.leagueoflegends [banned_by] => [media_embed] => stdClass Object ( ) [subreddit] => leagueoflegends [selftext_html] => [selftext] => [likes] => [user_reports] => Array ( ) [secure_media] => [link_flair_text] => [id] => 2papx0 [gilded] => 0 [secure_media_embed] => stdClass Object ( ) [clicked] => [report_reasons] => [author] => Azberg [media] => [score] => 2217 [approved_by] => [over_18] => [hidden] => [thumbnail] => self [subreddit_id] =>
I'd like to know how can I select only some of the items abovve - like domain, or likes, or anything. I tried but I can't manage it to work. Sorry for the newbiness - I really tried to fix this.
Thanks in advvance!
You should always use the latest API. Anyways, did you fill out the information in config.php?
According to the documentation, you have to "post the key and secret into the appropriate sections" in your config.php which is this file:
https://github.com/jcleblanc/reddit-php-sdk/blob/master/config.php
Specifically these two variables
...
static $CLIENT_ID = 'YOUR CLIENT ID';
static $CLIENT_SECRET = 'YOUR CLIENT SECRET';
...

How Do I access Data in Facebook Array with PHP?

I have made a simple facebook register widget.
On register the App sends the data to send.php
On send.php I have
print_r($response);
And I get something like this:
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1367953200
[issued_at] => 1367946138
[oauth_token] => BAAE0refKufgBAORkK7hUaVpF8MnFygoqHAHrO3nRJMyNjvJx6RjiMjoqbz2YlfqeogcIPGJJaIgD0xtxhBj1WRgQ5F5SidjwM7ZCKOyZBlEuatIqIccbjGj2uMV5hqtKtZA1g7hOEqMeZAEwmnO6SgRgsb9ittKZCDnPfoxYxCxZAZBAhIKX457IG5ZB4yknv9FZB8QUG7Pt0mfBRQUYG12KoTmO7QRH20LP65FyPqTi7mAZDZD
[registration] => Array
(
[name] => derp derp
[email] => ddddd#gmail.com
[location] => Array
(
[name] => Vienna, Austria
[id] => 1.1116511224109E+14
)
[gender] => male
[phone] => sss
)
[registration_metadata] => Array
(
[fields] => [ {'name':'name'}, {'name':'email'}, {'name':'location'}, {'name':'gender'}, {'name':'phone', 'description':'Phone Number', 'type':'text'},]
)
[user] => Array
(
[country] => at
[locale] => en_US
)
[user_id] => 100000506481284
)
So the data gets passed without a problem but how can I access a specific value?
For example text book array stuff doesnt appear to be working like:
print $response[0];
Gives me an error:
Notice: Undefined offset: 0 in C:\xampp\htdocs\ddd\send.php on line 38
How else can I access the data?
For example how could I store country, email, name or whatever in their own variables so I can echo them later? Its there but I cant seem to figure out how to "digest" it properly with php.
There is no index 0 in the array you pasted..
Use it like
$email = $response['registration']['email'];
If it was an object instead of an array you would do
$email = $response->registration->email
This is very basic PHP array handling.
http://php.net/manual/en/language.types.array.php

Facebook getting pages id issue using php

I have a facebook application and a tab page which links http://localhost/a/index.php, I have successfully add this tab page to my pages. I wrote in index.php
$checkLoggedIn = $facebook->getSignedRequest();
it return me like this
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1324648800
[issued_at] => 1324644411
[oauth_token] => AAACMkfuFjmIBAEJ9zqtJVvDK08aXlO1wSEFVNvekyCWcZBtnQcJ8BTCYfwZBMyrom5nazjPCsF56v4hLCBi2VywUzgrLSTYr9sbMmTWDN5QFFeOBfU
[page] => Array
(
[id] => 309081639123289
[liked] => 1
[admin] => 1
)
[user] => Array
(
[country] => bd
[locale] => en_US
[age] => Array
(
[min] => 21
)
)
[user_id] => 1549070809
)
its ok for me. I have also another link on that page is start.php with same code but it return to me like this
Array
(
[algorithm] => HMAC-SHA256
[code] => 2.AQAHgyMnInvOgkoU.3600.1324648800.5-1549070809|OMFOQPTFesejPmg0h2SfwwNGGEY
[issued_at] => 1324644436
[user_id] => 1549070809
)
what can I now? to get same object. because they are in same iframe.
This is because the facebook sdk only saves some information in the session (your second array). To remember the page, you have to manually save it.

Categories