Skip to main content

json - API Twitter + PHP + JSON_decode -


trying api of twitter, got problem... use url:

https://api.twitter.com/1/statuses/oembed.json?id=&align=center

i file_get_contents json , insert bd, before insert, see json have slashes , can json_decode, but, once string inserted, slashes disappear! cant json_decode when query sql, can do??

thank you!

json returned api twitter:

string(878) "{"type":"rich","provider_name":"twitter","height":null,"html":"\u003cblockquote class=\"twitter-tweet tw-align-center\" lang=\"es\"\u003e\u003cp\u003e\u00bfc\u00f3mo se llama esa cancion que suena \"aaronu ri lorunarenuronuaanale nararinunaloaalaiiaaranu reaa runaiiriiirorinaleaanatinurorela\"?\u003c\/p\u003e— comosuenaesa (@comosuenaesa) \u003ca href=\"https:\/\/twitter.com\/comosuenaesa\/status\/221453498653478914\" data-datetime=\"2012-07-07t04:00:03+00:00\"\u003ejulio 7, 2012\u003c\/a\u003e\u003c\/blockquote\u003e\n\u003cscript src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003e\u003c\/script\u003e","provider_url":"http:\/\/twitter.com","author_url":"https:\/\/twitter.com\/comosuenaesa","author_name":"comosuenaesa","cache_age":"31536000000","version":"1.0","url":"https:\/\/twitter.com\/comosuenaesa\/status\/221453498653478914","width":550}" 

from sql:

string(823) "{"type":"rich","author_url":"https://twitter.com/comosuenaesa","height":null,"html":"u003cblockquote class="twitter-tweet tw-align-center" lang="es"u003eu003cpu003eu00bfcu00f3mo se llama esa cancion que suena "aaronu ri lorunarenuronuaanale nararinunaloaalaiiaaranu reaa runaiiriiirorinaleaanatinurorela"?u003c/pu003e— comosuenaesa (@comosuenaesa) u003ca href="https://twitter.com/comosuenaesa/status/221453498653478914" data-datetime="2012-07-07t04:00:03+00:00"u003ejulio 7, 2012u003c/au003eu003c/blockquoteu003e u003cscript src="//platform.twitter.com/widgets.js" charset="utf-8"u003eu003c/scriptu003e","provider_name":"twitter","provider_url":"http://twitter.com","author_name":"comosuenaesa","cache_age":"31536000000","version":"1.0","url":"https://twitter.com/comosuenaesa/status/221453498653478914","width":550}" 

to insert json bd use class:

 public function defdata($ar, $table) { if(!empty($ar) , is_array($ar)) $this->data = $ar; else trigger_error('no array', e_user_error); if(!empty($table)) $this->table = $table; else trigger_error('no array', e_user_error); } public function insert() { $col = implode('`, `', array_keys($this->data)); $row = implode('\', \'', $this->data); $txt = 'insert `'.$this->table.'` (`'.$col.'`) values (\''.$row.'\')'; $this->setquery($txt); if($this->cmd()) return true; else return false; } 

and php code insert:

 $uri = 'https://api.twitter.com/1/statuses/oembed.json?id='.$_post['id_tw'].'&align=center'; $cnt = file_get_contents($uri); $data = array('json' => $cnt, 'type' => 1); $db = new database; $db->defdata($data, 'imagenes'); $id_img = ($db->insert()) ? $db->lastid() : false; 

json - api twitter + php + json_decode - stack overflow

learn, share, build

each month, on 50 million developers come stack overflow learn, share knowledge, , build careers.

join world’s largest developer community.

sign up

trying api of twitter, got problem... use url:

https://api.twitter.com/1/statuses/oembed.json?id=&align=center

i file_get_contents json , insert bd, before insert, see json have slashes , can json_decode, but, once string inserted, slashes disappear! cant json_decode when query sql, can do??

thank you!

json returned api twitter:

string(878) "{"type":"rich","provider_name":"twitter","height":null,"html":"\u003cblockquote class=\"twitter-tweet tw-align-center\" lang=\"es\"\u003e\u003cp\u003e\u00bfc\u00f3mo se llama esa cancion que suena \"aaronu ri lorunarenuronuaanale nararinunaloaalaiiaaranu reaa runaiiriiirorinaleaanatinurorela\"?\u003c\/p\u003e— comosuenaesa (@comosuenaesa) \u003ca href=\"https:\/\/twitter.com\/comosuenaesa\/status\/221453498653478914\" data-datetime=\"2012-07-07t04:00:03+00:00\"\u003ejulio 7, 2012\u003c\/a\u003e\u003c\/blockquote\u003e\n\u003cscript src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003e\u003c\/script\u003e","provider_url":"http:\/\/twitter.com","author_url":"https:\/\/twitter.com\/comosuenaesa","author_name":"comosuenaesa","cache_age":"31536000000","version":"1.0","url":"https:\/\/twitter.com\/comosuenaesa\/status\/221453498653478914","width":550}" 

from sql:

string(823) "{"type":"rich","author_url":"https://twitter.com/comosuenaesa","height":null,"html":"u003cblockquote class="twitter-tweet tw-align-center" lang="es"u003eu003cpu003eu00bfcu00f3mo se llama esa cancion que suena "aaronu ri lorunarenuronuaanale nararinunaloaalaiiaaranu reaa runaiiriiirorinaleaanatinurorela"?u003c/pu003e— comosuenaesa (@comosuenaesa) u003ca href="https://twitter.com/comosuenaesa/status/221453498653478914" data-datetime="2012-07-07t04:00:03+00:00"u003ejulio 7, 2012u003c/au003eu003c/blockquoteu003e u003cscript src="//platform.twitter.com/widgets.js" charset="utf-8"u003eu003c/scriptu003e","provider_name":"twitter","provider_url":"http://twitter.com","author_name":"comosuenaesa","cache_age":"31536000000","version":"1.0","url":"https://twitter.com/comosuenaesa/status/221453498653478914","width":550}" 

to insert json bd use class:

 public function defdata($ar, $table) { if(!empty($ar) , is_array($ar)) $this->data = $ar; else trigger_error('no array', e_user_error); if(!empty($table)) $this->table = $table; else trigger_error('no array', e_user_error); } public function insert() { $col = implode('`, `', array_keys($this->data)); $row = implode('\', \'', $this->data); $txt = 'insert `'.$this->table.'` (`'.$col.'`) values (\''.$row.'\')'; $this->setquery($txt); if($this->cmd()) return true; else return false; } 

and php code insert:

 $uri = 'https://api.twitter.com/1/statuses/oembed.json?id='.$_post['id_tw'].'&align=center'; $cnt = file_get_contents($uri); $data = array('json' => $cnt, 'type' => 1); $db = new database; $db->defdata($data, 'imagenes'); $id_img = ($db->insert()) ? $db->lastid() : false; 
share|improve question
    
some examples of code, , query loads. stands, query leads error. – daedalus jul 7 '12 @ 8:57
    
i dont nothing string: $c = file_get_contents... insert json = $c, when receive sql this: var_dump($t['json']); xd , see strings dont have slashes, , when try json_decode have error: syntax error, malformed json – kaseoga jul 7 '12 @ 8:58
    
no, don't see because still haven't provided asked for. please edit question above include correct information, formatted examples of current code. – daedalus jul 7 '12 @ 9:02
    
please provide correct query url. current 1 returns error. – daedalus jul 7 '12 @ 9:09
    
now @daedalus ? xd sorry! – kaseoga jul 7 '12 @ 9:12

your answer

 
discard

posting answer, agree privacy policy , terms of service.

browse other questions tagged or ask own question.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -