I'm trying to create a simple widget to retrieve a users feeds, I have fully set my application up to work with the #anywhere an OAuth functionality of twitter's API.
The problem I'm having is when I try to retrieve a users tweets and writing them out again to a text file.
My code for doing so is as follows
<?php
$cache = dirname(__FILE__) . '/../cache/twitter-json.txt';
$data = file_get_contents('http://api.twitter.com/1/statuses/user_timeline/screen_name.json?count=3&include_rts=true&include_entities=true');
$cachefile = fopen($cache, 'wb');
fwrite($cachefile,utf8_encode($data));
fclose($cachefile);
?>
okay now this code works great when I run the application locally but form some reason it does not work when I deploy it to the server.
It creates the cache file on the server and any test data I added to check if the file writing procedure worked.
I have not set up the server on my own it is run by an external company I'm just using ftp commands to deploy the web application
Any help and ideas would be appreciated
Check with your host - they have almost certainly disallowed file_get_contents for security reasons.
Your options are
Ask them to enable it by editing php.ini to allow_url_fopen
Use cURL to make the call
Here's a basic example using curl in php
$url = "http://api.twitter.com/1/statuses/user_timeline/screen_name.json?count=3&include_rts=true&include_entities=true"
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_URL,$url);
$data = curl_exec($curl_handle);
curl_close($curl_handle);
Related
Im working on a website using Laravel in a Docker container on local. The webserver used is Nginx.
Im trying to implement Facebook's Graph API (the PHP API) and as Im developing on localhost and using Docker, any time I want to use the API I get:
Can't Load URL: The domain of this URL isn't included in the app's
domains. To be able to load this URL, add all domains and subdomains
of your app to the App Domains field in your app settings.
I tried adding the domain I use locally myapp.local:3000, also <my ip>:3000 or localhost:3000 but nothing works.
Here is the code:
public function facebookRequest() {
$fb = new \Facebook\Facebook([
'app_id' => 'MY_APP_ID',
'app_secret' => 'MY_APP_SECRET',
'default_graph_version' => 'v8.0',
]);
$callback = 'users/get-facebook-photos';
$helper = $fb->getRedirectLoginHelper();
$permissions = ['user_photos'];
$data['fb_url'] = $helper->getLoginUrl($callback, $permissions);
$loginUrl = $helper->getLoginUrl(base_url().'/users/get-facebook-photos', $permissions);
echo 'Log in with Facebook!';
}
What I need to do to develop using Graph API and Docker? There's some option to bypass domain filter or what should I do?
Seems like you're using your application to request a token from facebook servers and when the token is created, you'll end up being redirected on to the original destination. The redirect location cannot be "localhost" it should be a valid location ... like a website. If you want to make this work locally you could edit your /etc/hosts file to map local.example.com to 127.0.0.1 and use this domain for redirections in tests/QA, so that when your app gets redirected, it attempts it via the localhost.
Another suggestion (found by searching for the exact but more generic parts of the error "Can't Load URL: The domain of this URL isn't included in the app's domains") suggests:
add "https://apps.facebook.com/" in valid OAuth redirect URIs under https://developers.facebook.com/apps/your-app-id/fb-login/settings/
Well finally got a solution (not the one I wanted). I was using a custom domain defined on my host file. That didn't work for Facebook. I needed to use localhost (not even 127.0.0.1) and whitelist localhost on Facebook Developers.
So, if you have this issue, you can do this workaround and use localhost instead of custom domain. Nevertheless, my ideal solution would be using custom domains.
I'm trying to set up OAuth to use between my website and Yahoo Fantasy Sports but getting the error message "Fatal error: Uncaught Error: Class 'OAuth' not found". I'm completely new to OAuth and the process described below is the first time I'm dabbling with this.
I've registered for a Yahoo API key and secret and am using them in this code in PHP to try to set up a basic test connection:
$o = new OAuth( $consumer_key, $consumer_secret,
OAUTH_SIG_METHOD_HMACSHA1,
OAUTH_AUTH_TYPE_URI );
Having searched here, I know I need an OAuth extension and PHPoAuthLib was recommended in another post. I've followed the instructions to install it on the web server via Composer (which basically seemed to be composer require lusitanian/oauth in SSH) but am still getting the "Uncaught Error" message. The php/ext folder on my server is empty and I'm don't know if that is a bad sign.
I've run a phpinfo() file on the server and it does not show oAuth. I've also read that I probably need to load the extension in a php.ini file on my server but I don't know exactly how I would do that for the PHPoAuthLib extension. I tried extension=oauth or extension=oauth.so but didn't seem to work.
Any help would be much appreciated! I'm not wedded to that particular extension (I've also seen a recommendation elsewhere for a Python Yahoo OAuth extension but I know nothing about Python or using 'pip')... I just feel like I'm going around in circles trying to figure out each step.
After trying both PHP and Python OAuth extensions mentioned above, it turned out my web hosting provider prevents custom installations via SSH on shared web hosting for security reasons, but was able to install the HTTP OAuth PEAR module that is available via cPanel to enable OAuth to be used.
We have the requirement to fetch an attachment to an Orbeon form from a simple automation script. We found the "List Forms Attachments" API (https://doc.orbeon.com/form-runner/api/persistence/list-form-data-attachments.html) and are trying to call it using a simple "curl" script that runs on the same host as the Orbeon Tomcat instance:
curl -v "http://localhost:8080/orbeon/fr/service/$app/$form/attachments?document=$docid"
This returns an HTTP 403 (Forbidden), and even after reading whatever doc we can find on Orbeon security, we're still scratching our heads over how to configure Orbeon. Is there a simple configuration example showing an Orbeon configuration that would allow the API to be called from a local script like ours? We are running Orbeon CE 2017.1.
If getting this API to work is an ordeal, the other option we'd consider would be a database solution. We have Orbeon running on a MySQL persistence layer, and the same script we're using also has access to this database. Is there an easy way to take a submitted form's XML and fetch the attachment for a given form field?
We see in the submitted form's XML that the attachment tag looks like this:
<File1 filename="Original Filename.doc" mediatype="application/msword" size="14236">
file:/tmp/tomcat7-tomcat7-tmp/xforms_upload_7266596219758922423.tmp?filename=Original+Filename+doc&mediatype=application%2Fmsword&size=14236&mac=fc2febb1227e93643a048fbb02abc16bba346531
</File1>
When we scan the orbeon_form_data_attach database table, we see a row with the file content we expect, but the file_name column doesn't match the file information in the form's XML above...in this example, the file_name on the database is 1af8cd16367470362e13f77e679c0ae590e1f4a5.bin. Some of our forms have multiple attachments, and there doesn't seem to be a direct way to go from the form XML to the file_name in the database table.
Either of these solutions would be fine for us - we just need a way to get the attachments for a form from a simple script.
For reference, the relevant documentation is Authorization of Pages and Services.
You can, although this is not to be done for production but only testing and development, open all services without authentication. See this section. Otherwise, you need to setup an authorization service.
https://github.com/devbridge/jQuery-Autocomplete
found this tutorial and was able to run it implement it on my app.my problem is, it wont run on local computer/app i think the problem is with mockjax is there way to make this tutorial run locally?or is there other way to make an autocomplete locally?this example is about autocomplete.
In the config lookup is for local data that doesn't rely on external requests. This would rely on loading in the data through JS on the client.
If you want to run it locally why not boot up a simple http server with python and make a get request to a local file?
See here line 133: https://github.com/michaelBenin/Airport-Distance-Calculator/blob/master/script.js
I currently have a website up and running that uses the Twitteroauth classes (abraham's) and the Twitter API. It is all working as it should, however, I want to also run the project on my localhost for debugging/coding purposes so that I am not in danger of messing up my live version.
I am wondering if it is possible to run Twitterouth on localhost. I know that there are ways to manipulate the callback URL of the application on Twitter's site, however I do not want to do that as my live version needs the callback URL.
I hope this makes sense and I hope there is a solution out there.
Thank you.
It is possible to run Twitteroauth in localhost. You should make a copy of your project files from your website and copy it to your localhost.
You might see a file "config.php" where you'll define the callback url.
define('OAUTH_CALLBACK', 'http://localhost/path_to_callback.php file');
It will redirect you to your callback.php file and it works in localhost.
For running Abramham William's twitteraouth locally , you can create another test application on twitter so that it don't disturb the live version . Then instead of using localhost/ in your address bar , you should use the IP address of your localhost , this mistake by me consumed a lot of time .
Example :
127.0.0.1/twittertest/index.php and not localhost/twittertest/index.php in your address bar .
You'll need to give the same oauth callback in your twitter application .