Dropbox FIle upload via API problem in PHP - php

I just stumbled over a problem using the Dropbox API.
Currently I am using the this lib: http://code.google.com/p/dropbox-php/
The problem is, if I upload a file I get a success but nothing arrives at the Dropbox.
I also "hacked" into the library and changed some of the post stuff. I can post it if you want.
Anybody got a solution for that?
Thanks!
//EDIT: I am using PHPs integrated OAuth functions
//EDIT2:
<?php
include "class/Dropbox/autoload.php";
$oauth = new Dropbox_OAuth_PHP("xxxxxxxxxxx", "xxxxxxxxxxx");
$dropbox = new Dropbox_API($oauth);
//re-login
if(isset($_SESSION["oauth_tokens"])) {
$my->oauth->setToken($_SESSION["oauth_tokens"]);
}
//uploads itself to DB
if($dropbox->putFile( basename(__FILE__), __FILE__ )) {
echo "Success";
} else {
echo "Fail :(";
}
sure this is not the complete code but assume that the user is logged in. :)

Dropbox for PHP, the library you're using to upload files to Dropbox, isn't maintained anymore and therefore may not function properly.
Try out PHP Dropbox Uploader. It is mentioned on the official Dropbox wiki.

Related

Issue with third party Google Analytics sdk

I have code which works above the php 5
its actually GA Library, here is its github project.
I have cloned the project theiconic/php-ga-measurement-protocol
Since I am new to PHP, I have no idea where to put this code, Please help me here this project should be installed via composer via code
{
"require": {
"theiconic/php-ga-measurement-protocol": "^2.0"
}
}
After this step I need to create a file something.php and I need to put the code below, I am having problem on locating autoload.php on my server, Please look at the code below to understand what i am saying.
<?php
//grab the data that Calendly sent in the webhook and store it in a variable called $objCalendlySubmission...
$objCalendlySubmission = json_decode(file_get_contents('php://input'));
//We've passed the Google client_id in Calendly's placeholder for utm_term. Feel free to pass it differently, this is just an example
if(property_exists($objCalendlySubmission->payload->tracking, 'utm_term') && !empty($objCalendlySubmission->payload->tracking->utm_term)) {
$strPageViewed = 'calendly_conversion.html'; // We use different page names depending on what type of event was scheduled via Calendly
sendGoogleAnalyticsPageView($objCalendlySubmission->payload->tracking->utm_term, $strPageViewed);
}
function sendGoogleAnalyticsPageView($strGAClientId, $strURL) {
require_once '/path_to_composer/composer/vendor/autoload.php'; //loads the PHP library for the "Google Analytics Measurement Protocol” **I dont know where is it located exactly on my xampp server, Please guide me here**
$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true); //you may have to adjust this path based on your setup **please help me here**
$analytics
->setProtocolVersion('1')
->setTrackingId('YOUR-GA-UA-ID-GOES-HERE')
->setClientId($strGAClientId)
->setDocumentLocationUrl($strURL);
$analytics->sendPageview();
}
?>
In the above code towards middle line
require_once '/path_to_composer/composer/vendor/autoload.php'; //loads the PHP library for the "Google Analytics Measurement Protocol”
I dont know where is it located exactly on my xampp server, Please guide me here
$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true); //you may have to adjust this path based on your setup
Here is the image of Project folder
Project structure Part 2

How to get an XML and integrate it into own website

I once was a Web-Designer who knew HTML/CSS. Now I'm a 3D animator, but I want to get back into the Web-Developer world.
But there's so much new to learn. E.g. flat file cms. Wow!
But my question for now is how I read an API, create the right PHP file to pull an XML file and put that data onto a web page.
Specificially I'm interested in this mobile.de API:
http://services.mobile.de/manual/search-api.html
And it seems that this is the XML that I need:
http://services.mobile.de/schema/ad-1.0.xsd
What are the next steps to get this beginner's project going?
I guess I need some sort of PHP file that uses GET and some sort of authentication. How can I test, if and what will come back?
And how do I use the pulled information to put in into a new page?
Or is my thinking all wrong?
Many thanks in advance.
Ben
Little bit you can understand through this post and answers on this post:
How to echo xml file in php
If you don't mind using already created library, please check : PHP Curl Class
Taken from the readme:
PHP Curl Class is an object-oriented wrapper of the PHP cURL extension that makes it easy to send HTTP requests and integrate with web APIs.
And this code snippet (also taken from the readme) could be your starting point:
$curl = new Curl();
$curl->setBasicAuthentication('username', 'password');
$curl->setUserAgent('');
$curl->setReferrer('');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setCookie('key', 'value');
$curl->get('http://www.example.com/');
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
}
else {
echo $curl->response;
}
var_dump($curl->requestHeaders);
var_dump($curl->responseHeaders);
Oh, and it's an unlicensed license type software.

Facebook php SDK - simple datafetch

I'm trying to integrate my facebook app with PHP. What I need to do is have users go to the app-page, authenticate the app and then somehow I want to end up with a variable that contains the info I need so I can store it in MySQL.
I downloaded the facebook SDK, but I cannot figure out how to make it work. All the examples I can find refer to a file called facebook.php - but there is no such file in the SDK (maybe the changed it?).
I managed to get it working with JavaScript, but I don't know how to get from JavaScript to php (the user object, that is).
I would prefer to just run it entirely through php. What I'm trying to do is very simple, but I don't understand what I'm doing wrong. The following, for instance, does not work:
<?php
FacebookSession::setDefaultApplication('appid', 'appsecret');
require facebook-php-sdk-v4-master\src\Facebook\FacebookCanvasLoginHelper.php;
$helper = new FacebookCanvasLoginHelper();
try {
$session = $helper->getSession();
} catch(FacebookRequestException $ex) {
echo "error";
} catch(\Exception $ex) {
echo "error 2";
}
if ($session) {
echo "logged in";
}
?>
Gives PHP Fatal error: Class 'FacebookSession' not found in
Where do I go? I don't think the Facebook getting started guide is helpful at all. It just starts out with "you have to do this" (what I did above) - but that doesn't work?
Looks like they changed the whole SDK for PHP 5.4.
Well there's a few options, you could go with the older SDK and all those tutorials you found will work for that. Or you could learn some new things!
I suggest that if you want to use the new Facebook SDK, you go ahead an learn about composer first, it makes including libraries a piece of cake and all you'd have to do is include the autoloader at the top of the file. Once done, you can just follow the example and it should work.
If you don't want to learn composer, you'll have to include all the required files manually. Here's a basic example.
In your example it looks like the error was because you were calling
FacebookSession::setDefaultApplication
Before you'd actually included the SDK

How do I get require_login()-like functionality using the new PHP Client Library for Facebook?

Howdy. I've been tasked with making a Facebook game, but I'm new to Facebook development, so I'm just getting started. Apologies in advance if this is a no-brainer to people.
I'm having trouble following all the examples I see on sites, and I keep running into missing pages in the Facebook documentation when I am trying to read up. I think it's because there's a new version of the PHP Client Library for Facebook, and everything I'm finding is referring to the old client.
For instance, I see this code in a lot of examples:
require 'facebook.php';
$facebook = new Facebook( array( 'appId' => '(id)', 'secret' => '(secret)' ) );
$facebook_account = $facebook->require_login();
...but there's no "require_login()" in the client library provided in the facebook.php file.
From what I can tell, it looks like Facebook has very recently rolled out some new system for development, but I don't see any sample code anywhere to deal with it. The new library comes with an "example.php" file, but it appears to be only for adding "Log in with Facebook" functionality to other sites (what I'm assuming is what they mean by "Facebook Connect" sites), not for just running apps in a Canvas page on Facebook itself.
Specifically, what I need to do is let users visit an application page within Facebook, have it bring up the dialog box allowing them to authorize the app, have it show up in their "games" page, and then have it pass me the relevant info about the user so I can start creating the game. But I can't seem to find any tutorials or examples that show how to do this using the new library. Seems like this should be pretty straightforward, but I'm running into roadblocks.
Or am I missing something about the PHP client library? Should require_login() be working for me, and there's something broken with my implementation, such as having the wrong client library or something? I downloaded from GitHub yesterday, so I'm pretty sure I have the most recent version of the code I have, but perhaps I'm downloading the wrong "facebook.php" file...?
The following is a rewrite of the old require_login function. It exactly duplicates the old functionality.
function facebook_require_login($required_permissions = '')
{
global $facebook; // NOTE GLOBAL FACEBOOK OBJECT, MUST ALREADY BE INSTANTIATED
$user = $facebook->get_loggedin_user();
$has_permissions = true;
if ($required_permissions) {
$facebook->require_frame();
$permissions = array_map('trim', explode(',', $required_permissions));
foreach ($permissions as $permission) {
if (!in_array($permission, $facebook->ext_perms)) {
$has_permissions = false;
break;
}
}
}
if ($user && $has_permissions) return $user;
$facebook->redirect(
$facebook->get_login_url(Facebook::current_url(), $facebook->in_frame(),
$required_permissions));
}
phpfour solution is the only correct one - since it utilizes the new php-sdk library from github.
The best solution is to edit the new facebook.php and add a require_login() function (so all existing pages who rely on it can stay the same)
public function require_login(){
if ( !$this->getSession() ) {
$url = $this->getLoginUrl( array(
'canvas' => 1,
'fbconnect' => 0
));
echo "<script type='text/javascript'>top.location.href = '$url';</script>";
}
else
return $this->getUser();
}
The new php script on git hub is a wraper for facebooks api, graph I presume but I've seen code for fql too so who knows. The forums are currently down and IRC was dead when I went across. I have been looking for the same solution as your require authorisation to call ->api(\me). Since the script extends another class if I remember right, you could try using the reflection class/function to see what methods are available. Hopefully some solid documentation is on its way! Please let me know if you solve this. (Sorry for poor formatting I'm on my mobile)
Well, I have been able to find a solution to the problem of authorizing application using the new PHP SDK. You can check my blog post here.
In short, you will need to get an authenticated session and then you can call the functions to get the logged in user's ID. In this case, you will call the "/me" path from the Graph API.

Image upload with Codeigniter, Redux and SWFUpload. "Not Authenticated" when browser uploads

I have an image upload form in a secured (with Redux) admin area of my website. When SWFAddress uploads it's not seen as logged in.
I created a multiple image upload form with SWFUpload and a back-end script with CodeIgniter. To cut a long painful story short - it all worked fine and dandy with the security turned off for testing purposes.
But when I turn the authentication back on, the uploader is getting my response "Not Authenticated" from the server? How can I make the form be authenticated?
He is my CI script:
<?php
class Api extends Controller {
function Api() {
parent::Controller();
// Check authentication by turning the security on
if ($this->redux_auth->logged_in())
else {
$this->_returnError('Not Authenticated');
exit;
}
}
function upload() {
// ... i've shortened this bit ...
if ( ! $this->upload->do_upload('Myfile'))
{
//echo "fail";
}
else
{
//echo "success";
}
}
I'm really out of my depth here, as I don't really much about how communication is actually handled by the browser and the server. Any help will be appreciated?!
I tried adding to
post_params: {"PHPSESSID" : "session->userdata('session_id'); ?>"},
To my instance os SWFObject. This didn't make and difference.
I can't get it to login by comparing the session ids. I've set up limited access to the upload script by comparing the upload IP with the users IP contained in the session. I am unsure of how safe this is.
btw, for anyone reading. in research I found out doing the necessary edits to the mimes.php files for swfupload allows for the upload of .php files. see here:
http://codeigniter.com/forums/viewthread/97399/P30/

Categories