Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for /picture and other "redirect" connections #13

Closed
wants to merge 2 commits into from

3 participants

@tristanlins

The /picture connection does not return any content, it returns a HTTP 302 response with a location header to the image.

I modified the makeRequest so the headers are readed and if the http status is 302, return the location header instead of an empty content.

Tristan Lins Support /picture and other redirect connections
The /picture connection does not return any content, it returns a HTTP
302 with a location header to the image.
Now makeRequest will return the new location, instead of null.
f94bb16
src/base_facebook.php
@@ -893,11 +897,32 @@ protected function makeRequest($url, $params, $ch=null) {
curl_close($ch);
throw $e;
}
+
+ if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 302) {
+ curl_close($ch);

Looks like you replaced spaces with tabs? I'd say you should use facebook's style to increase the chances of the pull being merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/base_facebook.php
((10 lines not shown))
curl_close($ch);
return $result;
}
/**
+ * Parse and store the response headers.
+ *
+ * @param $ch The curl handle
+ * @param string $header The response header
+ * @return int
+ */
+ public function readHeaders($ch, $header)
+ {

Facebook puts to opening curly on the same line as the declaration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/base_facebook.php
@@ -854,7 +854,11 @@ protected function makeRequest($url, $params, $ch=null) {
}
$opts = self::$CURL_OPTS;
- if ($this->getFileUploadSupport()) {
+
+ $this->headers = array();
+ $opts[CURLOPT_HEADERFUNCTION] = array(&$this, 'readHeaders');
+
+ if ($this->useFileUploadSupport()) {

useFileUploadSupport() is deprecated, please revert this to getFileUploadSupport()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tristanlins

I update my request according to the comments. Thx to @mikesherov

@gfosco
Collaborator

Sorry it took so long to respond to this. Can you sign the Contributor License Agreement? https://developers.facebook.com/opensource/cla

Once that's done we can look at this further. Thanks for your contribution.

@gfosco gfosco closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 11, 2012
  1. Support /picture and other redirect connections

    Tristan Lins authored
    The /picture connection does not return any content, it returns a HTTP
    302 with a location header to the image.
    Now makeRequest will return the new location, instead of null.
Commits on Mar 28, 2012
  1. Reformat to facebook coding style.

    Tristan Lins authored
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 0 deletions.
  1. +24 −0 src/base_facebook.php
View
24 src/base_facebook.php
@@ -854,6 +854,10 @@ protected function makeRequest($url, $params, $ch=null) {
}
$opts = self::$CURL_OPTS;
+
+ $this->headers = array();
+ $opts[CURLOPT_HEADERFUNCTION] = array(&$this, 'readHeaders');
+
if ($this->getFileUploadSupport()) {
$opts[CURLOPT_POSTFIELDS] = $params;
} else {
@@ -893,11 +897,31 @@ protected function makeRequest($url, $params, $ch=null) {
curl_close($ch);
throw $e;
}
+
+ if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 302) {
+ curl_close($ch);
+ return json_encode($this->headers['location']);
+ }
+
curl_close($ch);
return $result;
}
/**
+ * Parse and store the response headers.
+ *
+ * @param $ch The curl handle
+ * @param string $header The response header
+ * @return int
+ */
+ public function readHeaders($ch, $header) {
+ if (preg_match('#^([^:]+):(.*)$#', $header, $match)) {
+ $this->headers[strtolower($match[1])] = trim($match[2]);
+ }
+ return strlen($header);
+ }
+
+ /**
* Parses a signed_request and validates the signature.
*
* @param string $signed_request A signed token
Something went wrong with that request. Please try again.