Problems with Reddit SDK (API) - php

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';
...

Related

Woocommerce webhook not showing response

I am working on a webhook to notice when an order gets updated.
My webhook function looks like this:
public function webhook(Request $request) {
if(!empty(Request::header('x-wc-webhook-delivery-id'))) {
$head = Request::header('x-wc-webhook-source');
$site = preg_replace('{/$}', '', $head);
$webhookId = Request::header('x-wc-webhook-id');
$deliveryId = Request::header('x-wc-webhook-delivery-id');
$this->webhookOrders($site, $webhookId, $deliveryId);
}
}
So it will fire the webhookOrders function which is only getting the updated order by WebhookId & deliveryId:
$delivery = $woocommerce->get('webhooks/'.$webhookId.'/deliveries/'.$deliveryId);
Although the strange part is that when I try to access this get request through the webhook it is showing me an empty response:
Array
(
[id] => 559
[duration] =>
[summary] =>
[request_method] =>
[request_url] => https://<my_platform>/api/v1/orders/create
[request_headers] =>
[request_body] =>
[response_code] =>
[response_message] =>
[response_headers] =>
[response_body] =>
[date_created] => 2018-02-28T10:48:05
[_links] => Array
(
[self] => Array
(
[0] => Array
(
[href] => https://<my_woo_site>/wp-json/wc/v1/webhooks/0/deliveries/559
)
)
[collection] => Array
(
[0] => Array
(
[href] => https://<my_woo_site>/wp-json/wc/v1/webhooks/0/deliveries
)
)
[up] => Array
(
[0] => Array
(
[href] => https://<my_woo_site>/wp-json/wc/v1/webhooks/0
)
)
)
)
While in the Woocommerce admin panel it is showing me that there is content:
Also, the thing what's driving me crazy is that when I access the URL outside the webhook it is showing me the content. And the log files are not showing any error.
Hope someone knows the problem. Thanks!
Found the problem:
deliveries are not logged any more.
#deprecated 3.3.0 Webhooks deliveries logs now uses logging system.

How to find out Yahoo email address using Yahoo API PHP

so heres my predicament.
Currently using Yahoo API with PHP in order to use a 'Login with Yahoo' Function on my site.
I have managed to retrieve my entire profile. Trouble is, I can't directly display the primary email associated with the account.
If I use print_r($profile) I get everything dumped from my profile. It looks like this (personal data removed):
stdClass Object ( [uri] => http://social.yahooapis.com/v1/user/*********/profile [guid] => ***** [birthdate] => / [created] => 2010-04-22T20:47:48Z [emails] => Array ( [0] => stdClass Object ( [handle] => **#gmail.com [id] => 1 [type] => HOME ) [1] => stdClass Object ( [handle] => ****#yahoo.com [id] => 2 [primary] => 1 [type] => HOME ) ) [familyName] => Surname [gender] => M [givenName] => Ricki [image] => stdClass Object ( [height] => 192 [imageUrl] => http://l.yimg.com/dh/ap/social/profile/profile_b192.png [size] => 192x192 [width] => 192 ) [lang] => en-US [memberSince] => 2010-04-08T11:22:56Z [nickname] => Ricki [profileUrl] => http://profile.yahoo.com/*********** [updated] => 2013-03-03T18:12:22Z [isConnected] => )
Using $profile->emails->handle yields nothing however. Any ideas on what to do? I can use $profile->emails which returns an Array, displayed simply as 'Array' but if i try to select from the array i get an error:
"Catchable fatal error: Object of class stdClass could not be converted to string"
Anyone?
$profile->emails[0]->handle will give you the first handle in the system.
You can also do foreach($profile->emails as $email) { print $email->handle; }

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.

Facebook API couldn't connect to host and timeout errors

A few days ago I released a beta version of a game on Facebook.
Unfortunately, I'm not so lucky, and in the first most important days of the application when users first use it, they keep getting errors resulting from errors on my PHP Apache server which gets the following errors from Facebook API -
couldn't connect to host
connect() timed out!
My server runs on a free server I got from Joyent for facebook developers.
I'm not a big expert with web servers so I got no idea if the problems are from my side or Facebook side.
And how can I fix this problem quickly!
Thanks a lot!
Edit:
For some reason I forgot about the code samples and error examples -
Here's an example for a simple query against facebook -
$session = $facebook->getSession();
$currentID = $facebook->api('/me?fields=id');
Here's the error stack trace -
couldn't connect to host StackTrace: Array
(
[0] => Array
(
[file] => /users/home/aagnt2sv/web/public/Facebook/facebook-php-sdk-7d538d3/src/facebook.php
[line] => 523
[function] => makeRequest
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => https://graph.facebook.com/me?fields=id
[1] => Array
(
[method] => GET
[access_token] => 104269778819|2.AQAKqpIXE0jqFuoU.3600.1311008400.1-785849095|qxtBqmWWRMc_GpM77CK77RbO4YA
)
)
)
[1] => Array
(
[file] => /users/home/aagnt2sv/web/public/Facebook/facebook-php-sdk-7d538d3/src/facebook.php
[line] => 491
[function] => _oauthRequest
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => https://graph.facebook.com/me?fields=id
[1] => Array
(
[method] => GET
)
)
)
[2] => Array
(
[function] => _graph
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => /me?fields=id
)
)
[3] => Array
(
[file] => /users/home/aagnt2sv/web/public/Facebook/facebook-php-sdk-7d538d3/src/facebook.php
[line] => 444
[function] => call_user_func_array
[args] => Array
(
[0] => Array
(
[0] => Facebook Object
(
[appId:protected] => *censored*
[apiSecret:protected] => *censored*
[session:protected] => Array
(
[uid] => *censored*
[access_token] => 104269778819|2.AQAKqpIXE0jqFuoU.3600.1311008400.1-785849095|qxtBqmWWRMc_GpM77CK77RbO4YA
[expires] => 1311008400
[sig] => ddf14dcaa953cb64d3f98b0649b60613
)
[signedRequest:protected] =>
[sessionLoaded:protected] => 1
[cookieSupport:protected] => 1
[baseDomain:protected] =>
)
[1] => _graph
)
[1] => Array
(
[0] => /me?fields=id
)
)
)
[4] => Array
(
[file] => /users/home/aagnt2sv/web/public/edamometer/EdamometerWS.php
[line] => 31
[function] => api
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => /me?fields=id
)
)
Thanks again!
This was somehow fixed by itself after several days. Maybe it was a temporary problem on my server or on Facebook's servers.
Get user id with
$fb = new Facebook(array(
'appId' => 'your_app_id',
'secret' => 'your_app_secret',
));
$user = $fb->getUser();// returns user id
I'm currently having this problem with my server (using PHP to access the Facebook API), as well. Based upon the nature of the error message, obviously the problem is the connection between my server (running on the Amazon cloud, btw) and Facebook's server(s).
What is throwing me for a loop, though, is that some commands are working properly. That is, attempting to log in with one Facebook token is working fine, while another in causing this error message.
The only reasonable explanation I can come up with is that the Facebook servers are experiencing some sort of temporary hiccup... but even that does a poor job of explaining the problem, since it is somehow tied to the token which is being used. The only way it makes sense is if there's some sort of bug where Facebook's servers are timing out in processing the specific token I'm giving them...

Help with tweet media entities

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...

Categories