1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Catching Gdata Exceptions - Zend Framework Manual</title>
</head>
<body>
<table width="100%">
<tr valign="top">
<td width="85%">
<table width="100%">
<tr>
<td width="25%" style="text-align: left;">
<a href="zend.gdata.youtube.html">Using the YouTube Data API</a>
</td>
<td width="50%" style="text-align: center;">
<div class="up"><span class="up"><a href="zend.gdata.html">Zend_Gdata</a></span><br />
<span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
</td>
<td width="25%" style="text-align: right;">
<div class="next" style="text-align: right; float: right;"><a href="zend.http.html">Zend_Http</a></div>
</td>
</tr>
</table>
<hr />
<div id="zend.gdata.exception" class="section"><div class="info"><h1 class="title">Catching Gdata Exceptions</h1></div>
<p class="para">
The <span class="classname">Zend_Gdata_App_Exception</span> class is a base class
for exceptions thrown by <span class="classname">Zend_Gdata</span>. You can catch any exception
thrown by <span class="classname">Zend_Gdata</span> by catching
<span class="classname">Zend_Gdata_App_Exception</span>.
</p>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">try <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$client</span> =</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> Zend_Gdata_ClientLogin::<span style="color: #006600;">getHttpClient</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$username</span>, <span style="color: #0000ff;">$password</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span> catch<span style="color: #66cc66;">(</span>Zend_Gdata_App_Exception <span style="color: #0000ff;">$ex</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #808080; font-style: italic;">// Report the exception to the user</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/die"><span style="color: #000066;">die</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$ex</span>-><span style="color: #006600;">getMessage</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>
<p class="para">
The following exception subclasses are used by <span class="classname">Zend_Gdata</span>:
<ul class="itemizedlist">
<li class="listitem">
<p class="para">
<span class="classname">Zend_Gdata_App_AuthException</span>
indicates that the user's account credentials were not valid.
</p>
</li>
<li class="listitem">
<p class="para">
<span class="classname">Zend_Gdata_App_BadMethodCallException</span>
indicates that a method was called for a service
that does not support the method. For example,
the CodeSearch service does not support <span class="methodname">post()</span>.
</p>
</li>
<li class="listitem">
<p class="para">
<span class="classname">Zend_Gdata_App_HttpException</span>
indicates that an <acronym class="acronym">HTTP</acronym> request was not successful.
Provides the ability to get the full <span class="classname">Zend_Http_Response</span>
object to determine the exact cause of the failure in
cases where <strong class="command">$e->getMessage()</strong> does not provide
enough details.
</p>
</li>
<li class="listitem">
<p class="para">
<span class="classname">Zend_Gdata_App_InvalidArgumentException</span>
is thrown when the application provides a value that
is not valid in a given context. For example,
specifying a Calendar visibility value of "banana",
or fetching a Blogger feed without specifying
any blog name.
</p>
</li>
<li class="listitem">
<p class="para">
<span class="classname">Zend_Gdata_App_CaptchaRequiredException</span>
is thrown when a ClientLogin attempt receives a
<span_trademark class="trademark">CAPTCHA</span_trademark> challenge from the
authentication service. This exception contains a token
ID and a <acronym class="acronym">URL</acronym> to a <span_trademark class="trademark">CAPTCHA</span_trademark>
challenge image. The image is a visual puzzle that
should be displayed to the user. After
collecting the user's response to the challenge
image, the response can be included with the next
ClientLogin attempt.The user can alternatively be
directed to this website:
<tt class="uri">https://www.google.com/accounts/DisplayUnlockCaptcha</tt>
Further information can be found in the
<a href="zend.gdata.clientlogin.html" class="link">ClientLogin documentation</a>.
</p>
</li>
</ul>
</p>
<p class="para">
You can use these exception subclasses to handle specific exceptions
differently. See the <acronym class="acronym">API</acronym> documentation for information on which
exception subclasses are thrown by which methods in <span class="classname">Zend_Gdata</span>.
</p>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">try <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$client</span> = Zend_Gdata_ClientLogin::<span style="color: #006600;">getHttpClient</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$username</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$password</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$service</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span> catch<span style="color: #66cc66;">(</span>Zend_Gdata_App_AuthException <span style="color: #0000ff;">$authEx</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #808080; font-style: italic;">// The user's credentials were incorrect.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #808080; font-style: italic;">// It would be appropriate to give the user a second try.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> ...</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span> catch<span style="color: #66cc66;">(</span>Zend_Gdata_App_HttpException <span style="color: #0000ff;">$httpEx</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #808080; font-style: italic;">// Google Data servers cannot be contacted.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/die"><span style="color: #000066;">die</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$httpEx</span>-><span style="color: #006600;">getMessage</span><span style="color: #66cc66;">)</span>;<span style="color: #66cc66;">}</span></div></li></ol></div></div></div>
</div>
<hr />
<table width="100%">
<tr>
<td width="25%" style="text-align: left;">
<a href="zend.gdata.youtube.html">Using the YouTube Data API</a>
</td>
<td width="50%" style="text-align: center;">
<div class="up"><span class="up"><a href="zend.gdata.html">Zend_Gdata</a></span><br />
<span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
</td>
<td width="25%" style="text-align: right;">
<div class="next" style="text-align: right; float: right;"><a href="zend.http.html">Zend_Http</a></div>
</td>
</tr>
</table>
</td>
<td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
float: left;
width: 186px;
padding: 5px;
font-size: smaller;
}
ul.toc {
margin: 0px 5px 5px 5px;
padding: 0px;
}
ul.toc li {
font-size: 85%;
margin: 1px 0 1px 1px;
padding: 1px 0 1px 11px;
list-style-type: none;
background-repeat: no-repeat;
background-position: center left;
}
ul.toc li.header {
font-size: 115%;
padding: 5px 0px 5px 11px;
border-bottom: 1px solid #cccccc;
margin-bottom: 5px;
}
ul.toc li.active {
font-weight: bold;
}
ul.toc li a {
text-decoration: none;
}
ul.toc li a:hover {
text-decoration: underline;
}
</style>
<ul class="toc">
<li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
<li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
<li class="header up"><a href="reference.html">Zend Gdata Reference</a></li>
<li class="header up"><a href="zend.gdata.html">Zend_Gdata</a></li>
<li><a href="zend.gdata.analytics.html">Using Google Analytics</a></li>
<li><a href="zend.gdata.authsub.html">Authenticating with AuthSub</a></li>
<li><a href="zend.gdata.books.html">Using the Book Search Data API</a></li>
<li><a href="zend.gdata.clientlogin.html">Authenticating with ClientLogin</a></li>
<li><a href="zend.gdata.calendar.html">Using Google Calendar</a></li>
<li><a href="zend.gdata.docs.html">Using Google Documents List Data API</a></li>
<li><a href="zend.gdata.spreadsheets.html">Using Google Spreadsheets</a></li>
<li><a href="zend.gdata.gapps.html">Using Google Apps Provisioning</a></li>
<li><a href="zend.gdata.photos.html">Using Picasa Web Albums</a></li>
<li><a href="zend.gdata.youtube.html">Using the YouTube Data API</a></li>
<li class="active"><a href="zend.gdata.exception.html">Catching Gdata Exceptions</a></li>
</ul>
</td>
</tr>
</table>
</body>
</html>
|