当前位置:Gxlcms > PHP教程 > 【求指点】自学与新浪微博开放平台对接,运行新浪提供的SDK报错

【求指点】自学与新浪微博开放平台对接,运行新浪提供的SDK报错

时间:2021-07-01 10:21:17 帮助过:36人阅读

环境:Win7(x64)、Wamp集成(PHP5.4.3+MySQL5.5.24+Apache2.4.2+PHPMyAdmin3.5.1)
新浪PHP SDK版本:最老的那个(weibo-oauth-class-with-image-avatar-06-29-update)
目的:学做简易的微博,目的与新浪微博开放平台链接上
问题: 将一些" "WB_AKEY" "WB_SKEY"已申请,"WB_CALLBACK_URL"路径也改过了
-----------------------------------报错内容------------------------------------------
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Call to undefined function curl_init() in C:\wamp\www\PHP100\PHP100-sina\weibooauth.php on line 1687
Call Stack
# Time Memory Function Location
1 0.0008 250576 {main}( ) ..\index.php:0
2 0.0060 610864 WeiboOAuth->getRequestToken( ) ..\index.php:8
3 0.0060 611320 WeiboOAuth->oAuthRequest( ) ..\weibooauth.php:1575
4 0.0070 615504 WeiboOAuth->http( ) ..\weibooauth.php:1674

-------------------------------index.php部分代码------------------------------------
session_start();
//if( isset($_SESSION['last_key']) ) header("Location: weibolist.php");
include_once( 'config.php' );
include_once( 'weibooauth.php' );
$o = new WeiboOAuth( WB_AKEY , WB_SKEY );
$keys = $o->getRequestToken(); 报错行
if( strpos( "http://localhost/PHP100/PHP100-sina/" , 'index.php' ) === false )
$callback = 'http://localhost/PHP100/PHP100-sina/callback.php';
else
$callback = str_replace( 'index.php' , 'callback.php' , $_SERVER['SCRIPT_URI'] );
------------------------------weibooauth.php部分代码--------------------------------------
function getRequestToken($oauth_callback = NULL) {
$parameters = array();
if (!empty($oauth_callback)) {
$parameters['oauth_callback'] = $oauth_callback;
}
$request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters); 报错行
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
return $token;
}

===============================================================================================
function oAuthRequest($url, $method, $parameters , $multi = false) {

if (strrpos($url, 'http://') !== 0 && strrpos($url, 'http://') !== 0) {
$url = "{$this->host}{$url}.{$this->format}";
}
// echo $url ;
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
$request->sign_request($this->sha1_method, $this->consumer, $this->token);
switch ($method) {
case 'GET':
//echo $request->to_url();
return $this->http($request->to_url(), 'GET'); 报错行
default:
return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata($multi) , $multi );
}
}


回复讨论(解决方案)

Fatal error: Call to undefined function curl_init() ...
你没有加载 php_curl 扩展

Fatal error: Call to undefined function curl_init() ...
你没有加载 php_curl 扩展


include?

php.ini 中
extension=php_curl.dll

默认注释掉的
;extension=php_curl.dll

注意这个扩展需要 libeay32.dll 和 ssleay32.dll 支持库

php.ini 中
extension=php_curl.dll

默认注释掉的
;extension=php_curl.dll

注意这个扩展需要 libeay32.dll 和 ssleay32.dll 支持库


extension=php_curl.dll 把;去掉了
怎么查看libeay32.dll 和 ssleay32.dll?

在 php 安装目录中
你能用了就可以了,如果加载出错才需要做相关处理

在 php 安装目录中
你能用了就可以了,如果加载出错才需要做相关处理


libeay32.dll 和 ssleay32.dll
在php目录下都有

那不就行了?
重启一下 apache,再测试你的代码

那不就行了?
重启一下 apache,再测试你的代码


重启了,你说的dll文件system32,php文件夹下都有,还是
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Call to undefined function curl_init() in C:\wamp\www\PHP100\PHP100-sina\weibooauth.php on line 1687
Call Stack
# Time Memory Function Location
1 0.0005 251568 {main}( ) ..\index.php:0
2 0.0062 611880 WeiboOAuth->getRequestToken( ) ..\index.php:8
3 0.0062 612336 WeiboOAuth->oAuthRequest( ) ..\weibooauth.php:1575
4 0.0069 616528 WeiboOAuth->http( ) ..\weibooauth.php:1674
是不是因为我用的是php sdk最老的版本啊?
我又下个最新版的php sdk,但提示访问出错了!
你所访问的站点在新浪微博的认证失败,请你联系 作者 或者稍后再试。
(error:redirect_uri_mismatch)
是不是得等认证?才能本地测试,我在OAuth2.0 授权设置里也设置回调页面地址了

那不就行了?
重启一下 apache,再测试你的代码


谢谢版主!
我自己的问题,config。php回调地址我打成了http://http://………
脑子进水了
-------------------------------------------------------------------
授权页进去了,一切正常

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: keys in C:\wamp\www\PHP100\PHP100-sina\callback.php on line 9
Call Stack
# Time Memory Function Location
1 0.0003 250944 {main}( ) ..\callback.php:0

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: keys in C:\wamp\www\PHP100\PHP100-sina\callback.php on line 9
Call Stack
# Time Memory Function Location
1 0.0003 250944 {main}( ) ..\callback.php:0

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: oauth_verifier in C:\wamp\www\PHP100\PHP100-sina\callback.php on line 11
Call Stack
# Time Memory Function Location
1 0.0003 250944 {main}( ) ..\callback.php:0

( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Call to undefined function curl_init() in C:\wamp\www\PHP100\PHP100-sina\weibooauth.php on line 1687
Call Stack
# Time Memory Function Location
1 0.0003 250944 {main}( ) ..\callback.php:0
2 0.0040 611360 WeiboOAuth->getAccessToken( ) ..\callback.php:11
3 0.0040 611816 WeiboOAuth->oAuthRequest( ) ..\weibooauth.php:1611
4 0.0047 616016 WeiboOAuth->http( ) ..\weibooauth.php:1674
这又是肿么了????

引用 7 楼 xuzuning 的回复:那不就行了?
重启一下 apache,再测试你的代码
谢谢版主!
我自己的问题,config。php回调地址我打成了http://http://………
脑子进水了
-------------------------------------------------------------------
授权页进去了,一切正常……


config.php
session_start();

include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );
$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
if (isset($_REQUEST['code'])) {
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = WB_CALLBACK_URL;
try {
$token = $o->getAccessToken( 'code', $keys ) ;
} catch (OAuthException $e) {
}
}
--------------------------------
是不是我应该把WB_AKEY , WB_SKEY, WB_CALLBACK_URL;替换一下?

不是还有 Fatal error: Call to undefined function curl_init() in .... 吗?
你的 curl 根本就没有加载成功!

拷贝 libeay32.dll 和 ssleay32.dll 到 system32 中
由于你的操作系统是 64 位的,可能还需设置这两个文件以 32 位兼容方式运行

不是还有 Fatal error: Call to undefined function curl_init() in .... 吗?
你的 curl 根本就没有加载成功!

拷贝 libeay32.dll 和 ssleay32.dll 到 system32 中
由于你的操作系统是 64 位的,可能还需设置这两个文件以 32 位兼容方式运行


Fatal error: Call to undefined function curl_init() 问题终于解决了
现在的报错是
( ! ) Notice: Undefined index: keys in C:\wamp\www\PHP100\PHP100-sina\callback.php on line 9
Call Stack
# Time Memory Function Location
1 0.0004 250992 {main}( ) ..\callback.php:0

( ! ) Notice: Undefined index: keys in C:\wamp\www\PHP100\PHP100-sina\callback.php on line 9
Call Stack
# Time Memory Function Location
1 0.0004 250992 {main}( ) ..\callback.php:0

( ! ) Notice: Undefined index: oauth_verifier in C:\wamp\www\PHP100\PHP100-sina\callback.php on line 11
Call Stack
# Time Memory Function Location
1 0.0004 250992 {main}( ) ..\callback.php:0

( ! ) Notice: Undefined index: oauth_token in C:\wamp\www\PHP100\PHP100-sina\weibooauth.php on line 1613
Call Stack
# Time Memory Function Location
1 0.0004 250992 {main}( ) ..\callback.php:0
2 0.0050 607424 WeiboOAuth->getAccessToken( ) ..\callback.php:11

( ! ) Notice: Undefined index: oauth_token_secret in C:\wamp\www\PHP100\PHP100-sina\weibooauth.php on line 1613
Call Stack
# Time Memory Function Location
1 0.0004 250992 {main}( ) ..\callback.php:0
2 0.0050 607424 WeiboOAuth->getAccessToken( ) ..\callback.php:11
???????, ???????? ???б????
蓝色是个链接,一点会出现如下代码
----------------------------------------------------------------------------------

( ! ) Notice: Undefined index: oauth_token in C:\wamp\www\PHP100\PHP100-sina\weibolist.php on line 8
Call Stack
# Time Memory Function Location
1 0.0009 257280 {main}( ) ..\weibolist.php:0

( ! ) Notice: Undefined index: oauth_token_secret in C:\wamp\www\PHP100\PHP100-sina\weibolist.php on line 8
Call Stack
# Time Memory Function Location
1 0.0009 257280 {main}( ) ..\weibolist.php:0

( ! ) Notice: Undefined index: name in C:\wamp\www\PHP100\PHP100-sina\weibolist.php on line 14
Call Stack
# Time Memory Function Location
1 0.0009 257280 {main}( ) ..\weibolist.php:0
????~ ??????ô?

输入框,估计是新浪DEMO
?????????

输入框,估计是新浪DEMO
?????????

输入框,估计是新浪DEMO

( ! ) Warning: Illegal string offset 'text' in C:\wamp\www\PHP100\PHP100-sina\weibolist.php on line 52
Call Stack
# Time Memory Function Location
1 0.0009 257280 {main}( ) ..\weibolist.php:0
/

( ! ) Warning: Illegal string offset 'text' in C:\wamp\www\PHP100\PHP100-sina\weibolist.php on line 52
Call Stack
# Time Memory Function Location
1 0.0009 257280 {main}( ) ..\weibolist.php:0
4

( ! ) Warning: Illegal string offset 'text' in C:\wamp\www\PHP100\PHP100-sina\weibolist.php on line 52
Call Stack
# Time Memory Function Location
1 0.0009 257280 {main}( ) ..\weibolist.php:0
4

同问。。。。。。。。。。。。。。。。。。

人气教程排行